-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2.6.0 Add cache control string to the router #101
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -119,6 +119,12 @@ declare module "@luxuryescapes/router" { | |||||||||||
* @defaultValue `{}` | ||||||||||||
*/ | ||||||||||||
jsonOptions?: { [option: string]: string | number | boolean | null | undefined }; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Cache-Control header value | ||||||||||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control | ||||||||||||
*/ | ||||||||||||
cacheControlString?: string; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to abstract away the syntax and make it easier to use, e.g.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should, this would limit it too much, the spec is very wide and has many options that can be combined in different ways. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control |
||||||||||||
} | ||||||||||||
|
||||||||||||
interface SchemaRouteOptions { | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = exports = ({ cacheControlString }) => { | ||
return function responseCacheControl (req, res, next) { | ||
const originalFunc = res.json | ||
res.json = (responseBody) => { | ||
res.set('Cache-Control', cacheControlString) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should do something to check the res.status? |
||
return originalFunc.call(res, responseBody) | ||
} | ||
next() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this? I think theres a test file with some examples. Or I can add one for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add the test later todat