Skip to content

Commit

Permalink
rc8
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Oct 18, 2017
1 parent 988f4e4 commit 5b48693
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
36 changes: 18 additions & 18 deletions lib/index.js
Expand Up @@ -17,31 +17,31 @@ const internals = {
};


exports.register = function (server, options) {
exports.plugin = {
pkg: require('../package.json'),
once: true,

const settings = Hoek.applyToDefaults(internals.defaults, options);
register: function (server, options) {

server.expose('_etags', settings.etagsCacheMaxSize ? new Etag.Cache(settings.etagsCacheMaxSize) : null);
const settings = Hoek.applyToDefaults(internals.defaults, options);

server.decorate('handler', 'file', File.handler);
server.decorate('handler', 'directory', Directory.handler);
server.decorate('toolkit', 'file', function (path, responseOptions) {
server.expose('_etags', settings.etagsCacheMaxSize ? new Etag.Cache(settings.etagsCacheMaxSize) : null);

// Set correct confine value
server.decorate('handler', 'file', File.handler);
server.decorate('handler', 'directory', Directory.handler);
server.decorate('toolkit', 'file', function (path, responseOptions) {

responseOptions = responseOptions || {};
// Set correct confine value

if (typeof responseOptions.confine === 'undefined' || responseOptions.confine === true) {
responseOptions.confine = '.';
}
responseOptions = responseOptions || {};

Hoek.assert(responseOptions.end === undefined || +responseOptions.start <= +responseOptions.end, 'options.start must be less than or equal to options.end');
if (typeof responseOptions.confine === 'undefined' || responseOptions.confine === true) {
responseOptions.confine = '.';
}

return this.response(File.response(path, responseOptions, this.request));
});
};
Hoek.assert(responseOptions.end === undefined || +responseOptions.start <= +responseOptions.end, 'options.start must be less than or equal to options.end');

exports.register.attributes = {
pkg: require('../package.json'),
once: true
return this.response(File.response(path, responseOptions, this.request));
});
}
};
6 changes: 3 additions & 3 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "inert",
"description": "Static file and directory handlers plugin for hapi.js",
"version": "5.0.0-rc7",
"version": "5.0.0-rc8",
"repository": "https://github.com/hapijs/inert.git",
"main": "lib/index.js",
"keywords": [
Expand All @@ -15,7 +15,7 @@
"node": ">=8.0.0"
},
"peerDependencies": {
"hapi": "17.0.0-rc7"
"hapi": "17.0.0-rc8"
},
"dependencies": {
"ammo": "3.x.x",
Expand All @@ -26,7 +26,7 @@
},
"devDependencies": {
"code": "5.x.x",
"hapi": "17.0.0-rc7",
"hapi": "17.0.0-rc8",
"lab": "14.x.x"
},
"scripts": {
Expand Down
22 changes: 11 additions & 11 deletions test/directory.js
Expand Up @@ -536,36 +536,36 @@ describe('directory', () => {

it('resolves path name from plugin using specified path', async () => {

const plugin = (server, options) => {
const plugin = {
register: (server, options) => {

server.path(__dirname);
server.route({ method: 'GET', path: '/test/{path*}', config: { handler: { directory: { path: Path.join('.', 'directory'), index: false, listing: false } } } });
};
plugin.attributes = {
server.path(__dirname);
server.route({ method: 'GET', path: '/test/{path*}', config: { handler: { directory: { path: Path.join('.', 'directory'), index: false, listing: false } } } });
},
name: 'directory test',
version: '1.0'
};

const server = await provisionServer({ router: { stripTrailingSlash: false } });
server.register({ register: plugin }, {}, () => { });
await server.register(plugin);

const res = await server.inject('/test/index.html');
expect(res.statusCode).to.equal(200);
});

it('resolves path name from plugin using relative path', async () => {

const plugin = (server, options) => {
const plugin = {
register: (server, options) => {

server.route({ method: 'GET', path: '/test/{path*}', config: { handler: { directory: { path: Path.join('.', 'test', 'directory'), index: false, listing: false } } } });
};
plugin.attributes = {
server.route({ method: 'GET', path: '/test/{path*}', config: { handler: { directory: { path: Path.join('.', 'test', 'directory'), index: false, listing: false } } } });
},
name: 'directory test',
version: '1.0'
};

const server = await provisionServer({ router: { stripTrailingSlash: false } });
server.register({ register: plugin }, {}, () => { });
await server.register(plugin);

const res = await server.inject('/test/index.html');
expect(res.statusCode).to.equal(200);
Expand Down
2 changes: 1 addition & 1 deletion test/file.js
Expand Up @@ -37,7 +37,7 @@ describe('file', () => {

const defaults = { compression: { minBytes: 1 } };
const server = new Hapi.Server(Hoek.applyToDefaults(defaults, options || {}));
await server.register(etagsCacheMaxSize !== undefined ? { register: Inert, options: { etagsCacheMaxSize } } : Inert);
await server.register(etagsCacheMaxSize !== undefined ? { plugin: Inert, options: { etagsCacheMaxSize } } : Inert);
return server;
};

Expand Down

0 comments on commit 5b48693

Please sign in to comment.