Skip to content

Commit

Permalink
Merge pull request #79 from kanongil/directory-path-fix
Browse files Browse the repository at this point in the history
Manually extract last param name from path
  • Loading branch information
kanongil authored Dec 21, 2016
2 parents 93b387a + 22304de commit ed46993
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ exports.handler = function (route, options) {
const settings = Joi.attempt(options, internals.schema, 'Invalid directory handler options (' + route.path + ')');
Hoek.assert(route.path[route.path.length - 1] === '}', 'The route path for a directory handler must end with a parameter:', route.path);

const paramName = /\w+/.exec(route.path.slice(route.path.lastIndexOf('{')))[0];

const normalize = (paths) => {

const normalized = [];
Expand Down Expand Up @@ -77,7 +79,7 @@ exports.handler = function (route, options) {

// Append parameter

const selection = request.paramsArray[request.paramsArray.length - 1];
const selection = request.params[paramName];
if (selection &&
!settings.showHidden &&
internals.isFileHidden(selection)) {
Expand Down
13 changes: 13 additions & 0 deletions test/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ describe('directory', () => {
});
});

it('returns the "index.html" index file when route contains multiple path segments', (done) => {

const server = provisionServer();
server.route({ method: 'GET', path: '/directory{index}/{path*}', handler: { directory: { path: './directory/' } } });

server.inject('/directoryIndex/', (res) => {

expect(res.statusCode).to.equal(200);
expect(res.payload).to.contain('<p>test</p>');
done();
});
});

it('returns the index file when found and single custom index file specified', (done) => {

const server = provisionServer();
Expand Down

0 comments on commit ed46993

Please sign in to comment.