Skip to content

Commit

Permalink
feat: set cache-control header (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffroy Empain committed Mar 9, 2021
1 parent 3e0151a commit 09621ea
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/caddy/config/sites/generate-site-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,24 @@ function get401ErrorRoute() {
};
}

// https://caddyserver.com/docs/json/apps/http/servers/routes/handle/headers/
const cacheHandler = {
handler: 'headers',
response: {
set: {
'Cache-Control': ['public', 'max-age=0', 'must-revalidate'],
},
},
};

function getPrimaryRoute(site: Site, branch: Branch) {
const branchDirInCaddy = getBranchDirInCaddy(site._id, branch._id);

const fileHandler = {
handler: 'file_server',
root: branchDirInCaddy,
};

if (site.spa) {
return {
match: [{
Expand All @@ -97,17 +113,16 @@ function getPrimaryRoute(site: Site, branch: Branch) {
handler: 'rewrite',
uri: '{http.matchers.file.relative}',
},
{
handler: 'file_server',
root: branchDirInCaddy,
},
cacheHandler,
fileHandler,
],
};
}

return {
handle: [{
handler: 'file_server',
root: branchDirInCaddy,
}],
handle: [
cacheHandler,
fileHandler,
],
};
}

0 comments on commit 09621ea

Please sign in to comment.