json-server
json-server copied to clipboard
Set cache-control for static files
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
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();
});