-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af4e5f0
commit 0272560
Showing
6 changed files
with
52 additions
and
11 deletions.
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 |
---|---|---|
|
@@ -39,13 +39,19 @@ exports = module.exports = internals.Route = function (route, connection, plugin | |
|
||
Hoek.assert(route.path, 'Route missing path'); | ||
const routeDisplay = route.method + ' ' + route.path; | ||
Hoek.assert(route.handler || (route.config && route.config.handler), 'Missing or undefined handler:', routeDisplay); | ||
Hoek.assert(!!route.handler ^ !!(route.config && route.config.handler), 'Handler must only appear once:', routeDisplay); // XOR | ||
|
||
let config = route.config; | ||
if (typeof config === 'function') { | ||
config = config.call(realm.settings.bind, connection.server); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AdriVanHoudt
Contributor
|
||
} | ||
|
||
Hoek.assert(route.handler || (config && config.handler), 'Missing or undefined handler:', routeDisplay); | ||
Hoek.assert(!!route.handler ^ !!(config && config.handler), 'Handler must only appear once:', routeDisplay); // XOR | ||
Hoek.assert(route.path === '/' || route.path[route.path.length - 1] !== '/' || !connection.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when connection configured to strip:', routeDisplay); | ||
|
||
route = Schema.apply('route', route, routeDisplay); | ||
|
||
const handler = route.handler || route.config.handler; | ||
const handler = route.handler || config.handler; | ||
const method = route.method.toLowerCase(); | ||
Hoek.assert(method !== 'head', 'Method name not allowed:', routeDisplay); | ||
|
||
|
@@ -54,7 +60,7 @@ exports = module.exports = internals.Route = function (route, connection, plugin | |
const handlerDefaults = Handler.defaults(method, handler, connection.server); | ||
let base = Hoek.applyToDefaultsWithShallow(connection.settings.routes, handlerDefaults, ['bind']); | ||
base = Hoek.applyToDefaultsWithShallow(base, realm.settings, ['bind']); | ||
this.settings = Hoek.applyToDefaultsWithShallow(base, route.config || {}, ['bind']); | ||
this.settings = Hoek.applyToDefaultsWithShallow(base, config || {}, ['bind']); | ||
this.settings.handler = handler; | ||
this.settings = Schema.apply('routeConfig', this.settings, routeDisplay); | ||
|
||
|
@@ -95,8 +101,8 @@ exports = module.exports = internals.Route = function (route, connection, plugin | |
|
||
// Assert on config, not on merged settings | ||
|
||
Hoek.assert(!route.config || !route.config.payload, 'Cannot set payload settings on HEAD or GET request:', routeDisplay); | ||
Hoek.assert(!route.config || !route.config.validate || !route.config.validate.payload, 'Cannot validate HEAD or GET requests:', routeDisplay); | ||
Hoek.assert(!config || !config.payload, 'Cannot set payload settings on HEAD or GET request:', routeDisplay); | ||
Hoek.assert(!config || !config.validate || !config.validate.payload, 'Cannot validate HEAD or GET requests:', routeDisplay); | ||
|
||
validation.payload = null; | ||
} | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Any reason not to call it with the
server
andpluginOptions
relevant to the current realm? That's what I usually see folks closing around their route configs.