Add support for overriding settings per request #2935
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds
res.settings
, an object on to which properties can be defined that will override application settings within Express internals (the values returned fromapp.get()
are not altered, therefore any middleware/components that wants to respect the override would need to be updated to useres.settings
instead ofapp.get()
).At present, this affects the following settings:
The
res.settings
object is passed through to view rendering code by adding property_settings
to theoptions
parameter ofapp.render()
.The entry key for the view cache was changed to prepend the
views
setting to ensure the cache continues to work correctly ifviews
is overridden to a different value (eg if view'users'
was cachedfrom
/projdir/views/a
butviews
was overridden to point to/projdir/views/b
for this request, it should not retrieve the'users'
view from the cache for/projdir/views/a
).res.settings
sets its__proto__
to be thesettings
property of the current application so settings read from the object will default to the application settings.As the request progresses through routing, the
__proto__
will be updated to ensure values always defalt to the settings of the current application.Fixes #2849