Skip to content

Commit 60c5b53

Browse files
author
Eran Hammer
committed
Closes hapijs#1208
1 parent ceffbe0 commit 60c5b53

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/files.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var internals = {};
1414
exports.fileHandler = function (route, options) {
1515

1616
var settings = (typeof options !== 'object' ? { path: options } : Utils.clone(options)); // options can be reused
17-
Utils.assert(typeof settings.path !== 'string' || settings.path[settings.path.length - 1] !== '/', 'File path cannot end with a \'/\'');
17+
Utils.assert(typeof settings.path !== 'string' || settings.path[settings.path.length - 1] !== '/', 'File path cannot end with a \'/\':', route.path);
1818

1919
var absolutePath = internals.absolutePath(route);
2020

@@ -53,8 +53,8 @@ exports.fileHandler = function (route, options) {
5353

5454
exports.directoryHandler = function (route, options) {
5555

56-
Utils.assert(route.path[route.path.length - 1] === '}', 'The route path must end with a parameter');
57-
Utils.assert(route.params.length >= 1, 'The route path must include at least one parameter');
56+
Utils.assert(route.path[route.path.length - 1] === '}', 'The route path must end with a parameter:', route.path);
57+
Utils.assert(route.params.length >= 1, 'The route path must include at least one parameter:', route.path);
5858

5959
var settings = Utils.clone(options); // options can be reused
6060
var absolutePath = internals.absolutePath(route);
@@ -82,7 +82,7 @@ exports.directoryHandler = function (route, options) {
8282
if (Array.isArray(settings.path)) {
8383
settings.path.forEach(function (path) {
8484

85-
Utils.assert(path && typeof path === 'string', 'Directory path array must only contain strings');
85+
Utils.assert(path && typeof path === 'string', 'Directory path array must only contain strings:', route.path);
8686
normalized.push(normalize(path));
8787
});
8888
}
@@ -127,8 +127,6 @@ exports.directoryHandler = function (route, options) {
127127

128128
internals.absolutePath = function (route) {
129129

130-
var relativeTo = route.server.settings.files && route.server.settings.files.relativeTo;
131-
Utils.assert(relativeTo && (relativeTo[0] === '/' || ['cwd', 'routes'].indexOf(relativeTo) !== -1), 'Invalid server files.relativeTo configuration');
132130

133131
// Plugin
134132

@@ -138,6 +136,7 @@ internals.absolutePath = function (route) {
138136

139137
// 'cwd'
140138

139+
var relativeTo = route.server.settings.files.relativeTo;
141140
if (relativeTo === 'cwd') {
142141
return '.';
143142
}

lib/schema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ internals.serverSchema = {
7979
request: Joi.array()
8080
}).allow(false),
8181
files: Joi.object({
82-
relativeTo: Joi.string()
82+
relativeTo: [
83+
Joi.string().valid('cwd', 'routes').required(),
84+
Joi.string().regex(/^\//).required()
85+
]
8386
}).allow(false, true),
8487
json: Joi.object({
8588
replacer: [Joi.func().allow(null), Joi.array()],

0 commit comments

Comments
 (0)