Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Assert = require('assert');
const Http = require('http');

const Bounce = require('@hapi/bounce');
const Catbox = require('@hapi/catbox');
Expand All @@ -19,7 +20,9 @@ const Streams = require('./streams');
const Validation = require('./validation');


const internals = {};
const internals = {
httpVerbs: new Set([...Http.METHODS.map((s) => s.toLowerCase()), '*', '_special'])
};


exports = module.exports = internals.Route = class {
Expand All @@ -35,6 +38,7 @@ exports = module.exports = internals.Route = class {

const method = route.method.toLowerCase();
Hoek.assert(method !== 'head', 'Cannot set HEAD route:', route.path);
Hoek.assert(internals.httpVerbs.has(method), 'Unsupported "method" for route:', route.method, route.path);

const path = realm.modifiers.route.prefix ? realm.modifiers.route.prefix + (route.path !== '/' ? route.path : '') : route.path;
Hoek.assert(path === '/' || path[path.length - 1] !== '/' || !core.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when configured to strip:', route.method, route.path);
Expand Down
9 changes: 9 additions & 0 deletions test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ describe('Route', () => {
}).to.throw(/Invalid route options/);
});

it('throws an error when a route uses an engine unsupported method', () => {

expect(() => {

const server = Hapi.server();
server.route({ method: 'HAPIIII', path: '/', handler: () => null });
}).to.throw(/Unsupported "method" for route/);
});

it('throws an error when a route uses the HEAD method', () => {

expect(() => {
Expand Down