File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed
Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -13,15 +13,18 @@ async function getData() {
1313
1414 if ( assets ) {
1515 const path = assets === "/" ? "/index.html" : assets ;
16+ const cache = assets !== "/" ;
1617
1718 return {
18- api : "assets" ,
19- query : { path : `/var/apps/code.editor/target/server/dist${ path } ` } ,
19+ env,
20+ api : "read" ,
21+ query : { path : `/var/apps/code.editor/target/server/dist${ path } ` , cache } ,
2022 body : { } ,
2123 } ;
2224 }
2325
2426 const result = {
27+ env,
2528 api : env . HTTP_API_PATH || "" ,
2629 query : querystring . parse ( env . QUERY_STRING || "" ) ,
2730 body : { } ,
Original file line number Diff line number Diff line change @@ -20,6 +20,17 @@ module.exports = async function read({ query }) {
2020 const testFd = fs . openSync ( path , "r" ) ;
2121 fs . closeSync ( testFd ) ;
2222
23+ if ( query . cache ) {
24+ const maxAge = 365 * 24 * 60 * 60 ;
25+
26+ console . log ( `Cache-Control: public, max-age=${ maxAge } , immutable` ) ;
27+ console . log (
28+ `Expires: ${ new Date ( Date . now ( ) + maxAge * 1000 ) . toUTCString ( ) } `
29+ ) ;
30+ console . log ( `Last-Modified: ${ stat . mtime . toUTCString ( ) } ` ) ;
31+ console . log ( `ETag: "${ stat . size } -${ stat . mtime . getTime ( ) } "` ) ;
32+ }
33+
2334 return {
2435 code : 200 ,
2536 msg : "操作成功" ,
Original file line number Diff line number Diff line change 11const getType = require ( "./type" ) ;
22
33const router = {
4- assets : { type : "file" , run : require ( "../router/read" ) } ,
54 read : { type : "file" , run : require ( "../router/read" ) } ,
65 save : { run : require ( "../router/save" ) } ,
76} ;
You can’t perform that action at this time.
0 commit comments