Skip to content

Commit

Permalink
stricter cache-control directives. fix #42
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Jun 12, 2024
1 parent fb609f9 commit 0004705
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source/server/routes/api/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const router = Router();
*/
router.use((req, res, next)=>{
//Browser should always make the request
res.set("Cache-Control", "max-age=0, must-revalidate");
res.set("Cache-Control", "no-cache");
next();
});

Expand Down
2 changes: 1 addition & 1 deletion source/server/routes/api/v1/scenes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default async function getScenes(req :Request, res :Response){
if(lastModified < mtime) lastModified = mtime;
}

res.append("Cache-Control", "private");
res.set("Cache-Control", "no-cache, private");
res.set("ETag", "W/"+eTag.digest("base64url"));
res.set("Last-Modified", new Date(lastModified).toUTCString());
if( req.fresh){
Expand Down
3 changes: 2 additions & 1 deletion source/server/routes/scenes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const router = Router();
* Settings can be changed individually further down the line
*/
router.use((req, res, next)=>{
res.set("Cache-Control", "max-age=0, must-revalidate");
res.set("Access-Control-Allow-Origin", "*");
res.set("Cache-Control", "no-cache, private");
next();
});

Expand Down
15 changes: 5 additions & 10 deletions source/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,15 @@ export default async function createServer(config = defaultConfig) :Promise<expr
/**
* Set permissive cache-control for ui pages
*/
app.use(["/ui", "/js", "/css", "/doc", "/language"], (req, res, next)=>{
app.use("/ui", (req :express.Request, res:express.Response, next)=>{
res.set("Cache-Control", `max-age=${30*60}, public`);
next();
});
/**
* Set even more permissive cache-control for static assets
*/
app.use(["/images", "/fonts", "/favicon.png"], (req, res, next)=>{
res.set("Cache-Control", `max-age=${60*60*24*30*12}, public`);
next();
});


//Ideally we would like a really long cache time for /dist but it requires unique filenames for each build
//Allow CORS for assets that might get embedded
app.use(["/dist", "/scenes"], (req, res, next)=>{
app.use("/dist", (req, res, next)=>{
res.set("Cache-Control", `max-age=${30*60}, public`);
res.set("Access-Control-Allow-Origin", "*");
next();
});
Expand Down

0 comments on commit 0004705

Please sign in to comment.