-
-
Notifications
You must be signed in to change notification settings - Fork 17.1k
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
Add app.createRouter function #3623
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var express = require('../') | ||
var assert = require('assert') | ||
|
||
describe('app.createRouter()', function () { | ||
|
||
it('should create a router that inherits settings from app.settings', function () { | ||
var app = express() | ||
app.set('strict routing', true) | ||
app.set('case sensitive routing', true) | ||
|
||
var router = app.createRouter() | ||
|
||
assert(router.strict, 'Router did not inherit strict option from app.settings') | ||
assert(router.caseSensitive, 'Router did not inherit case sensitive option from app.settings') | ||
}) | ||
|
||
it('should allow options param to override app.settings when creating router', function () { | ||
var app = express() | ||
app.set('strict routing', true) | ||
app.set('case sensitive routing', false) | ||
|
||
var router = app.createRouter({ | ||
strict: false, | ||
caseSensitive: true | ||
}) | ||
|
||
assert.equal(router.strict, false, 'options param strict did not override app.settings') | ||
assert.equal(router.caseSensitive, true, 'options param caseSensitive did not override app.settings') | ||
}) | ||
}) |
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.
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.
This is mostly just a style thing, so if there is strong opposition feel free to ignore me, but I find that reducing the code required to achieve the same result often reduces maintenance and understanding costs in the future. For example, this could be written much more succinctly as follows:
Sometimes more lines of code is a good thing for clarity, but in this case, there are a bunch of lines which can be achieved with one usage of a ternary. This also has the upside of not unnecessarily calling
this.enabled
if you pass the option.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 like that we don't have to call this.enabled if the options are passed in, that's good. But to me this looks like a jumbled mess. It takes multiple seconds to decode what it actually means while undefined checks are really easy to make sense of imo.
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.
Like I said, mostly a style thing :), but maybe you can find a middle ground without the unnecessary calls?
Also, technically it is just the same
undefined
checks you had but in a single line. Maybe other people like the more verbose syntax with the same result, I don't know and it probably shouldn't be the focus of any more energy.