Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #6 from rocjs/feature/static-maxage
Browse files Browse the repository at this point in the history
Add support for max-age in the koa static middleware through settings
  • Loading branch information
dlmr committed Apr 22, 2016
2 parents 0e949e1 + 6c99769 commit 7ecba1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/roc-package-web-app/app/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ export default function createServer(options = {}, beforeUserMiddlewares = []) {

const makeServe = (toServe = []) => {
toServe = [].concat(toServe);

const staticSettings = process.env.NODE_ENV === 'production' ? runtimeSettings.koa.staticServe : {};

for (const path of toServe) {
// We use defer here to no try to fetch a file if we have set something on body, something that is done in
server.use(serve(path, {
// We use defer as default here to no try to fetch a file
// if we have set something on body, something that is done in
// redirect. This because https://github.com/koajs/send/issues/51
server.use(serve(path, { defer: true }));
defer: true,
...staticSettings
}));
}
};

Expand Down
3 changes: 3 additions & 0 deletions packages/roc-package-web-app/src/config/roc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default {
trailingSlashes: {
enabled: true,
defer: true
},
staticServe: {
maxage: 60000
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/roc-package-web-app/src/config/roc.config.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default {
trailingSlashes: {
enabled: 'Set to true to enforce trailing slashes, false to remove them and null for no rule.',
defer: 'If this should be performed after looking for a file on disk.'
},
staticServe: {
maxage: 'Browser cache max-age in milliseconds. Production only.'
}
}
}
Expand Down

0 comments on commit 7ecba1b

Please sign in to comment.