json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Set cache-control for static files

Open apollocoder opened this issue 6 years ago • 1 comments

Good day everyone

Is it possible to set/overwrite the response header 'cache-control' when serving files via the --static flag? The middleware does not seem to apply for static files.

Kind regards

apollocoder avatar Apr 19 '18 07:04 apollocoder

If someone comes across this question, there is an answer

You need to add this to your server setup:

server.use((req, res, next) => {
  res.header("Cache-Control", "public, max-age=86400000"); // change max-age to any value in milliseconds you want
  next();
});

nikitalpopov avatar Oct 20 '21 17:10 nikitalpopov