Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "errorh", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Gene Diaz <genediazjr@gmail.com> (http://genediazjr.com/)", | ||
@@ -5,0 +5,0 @@ "description": "Custom error pages for Hapi", |
# errorh | ||
Custom static error pages for Hapi. | ||
This plugin depends on [inert](https://github.com/hapijs/inert) to [function](https://github.com/hapijs/inert#customized-file-response). | ||
**This plugin depends on [inert](https://github.com/hapijs/inert) to [function](https://github.com/hapijs/inert#customized-file-response).** | ||
@@ -8,3 +8,3 @@ Similarly, please ensure that the [route files](https://github.com/hapijs/hapi/blob/master/API.md#route.config.files) are configured. | ||
If not, you may use the `staticRoute` option to specify one. | ||
If not, you may use the `staticRoute` option to [specify one](https://github.com/hapijs/inert#the-directory-handler). | ||
@@ -20,2 +20,14 @@ [![npm version](https://badge.fury.io/js/errorh.svg)](https://badge.fury.io/js/errorh) | ||
```js | ||
// configuring route files | ||
const server = new Hapi.Server({ | ||
connections: { | ||
routes: { | ||
files: { | ||
relativeTo: '/path/to/files' | ||
} | ||
} | ||
} | ||
}); | ||
// registering the plugin | ||
server.register({ | ||
@@ -26,3 +38,3 @@ register: require('errorh'), | ||
404: '404.html', | ||
default: 'error.html' | ||
default: '50x.html' | ||
}, | ||
@@ -61,3 +73,3 @@ staticRoute: { | ||
* **errorFiles** - `object` containing the status code to file config. | ||
* **staticRoute** - `route object` for setting up the inert static file route. | ||
* **staticRoute** - `route object` for setting up the inert static [directory handler](https://github.com/hapijs/inert#the-directory-handler). | ||
@@ -64,0 +76,0 @@ ## Contributing |
@@ -95,4 +95,6 @@ 'use strict'; | ||
404: '404.html' | ||
}, | ||
staticRoute: { | ||
} | ||
}, (err) => { | ||
server.route({ | ||
path: '/{path*}', | ||
@@ -107,4 +109,3 @@ method: '*', | ||
} | ||
} | ||
}, (err) => { | ||
}); | ||
@@ -124,3 +125,12 @@ expect(err).to.not.exist(); | ||
return done(); | ||
server.inject({ | ||
method: 'get', | ||
url: '/test' | ||
}, (res) => { | ||
expect(res.statusCode).to.be.equal(404); | ||
expect(res.result).to.equal('Sorry, that page doesn’t exist.\n'); | ||
return done(); | ||
}); | ||
}); | ||
@@ -130,3 +140,3 @@ }); | ||
it('loads static routes', (done) => { | ||
it('uses staticRoutes', (done) => { | ||
@@ -183,2 +193,88 @@ register({ | ||
}); | ||
it('doesnt work without configured route files', (done) => { | ||
const someServer = new Hapi.Server({ debug: false }); | ||
someServer.connection(); | ||
someServer.route({ | ||
method: 'get', | ||
path: '/error', | ||
handler: (request, reply) => { | ||
return reply(Boom.badImplementation()); | ||
} | ||
}); | ||
someServer.route({ | ||
method: 'get', | ||
path: '/none', | ||
handler: (request, reply) => { | ||
return reply(Boom.notImplemented()); | ||
} | ||
}); | ||
someServer.register([ | ||
Inert, | ||
{ | ||
register: Plugin, | ||
options: { | ||
errorFiles: { | ||
404: '404.html', | ||
default: '50x.html' | ||
}, | ||
staticRoute: { | ||
path: '/{path*}', | ||
method: '*', | ||
handler: { | ||
directory: { | ||
path: './', | ||
index: true, | ||
redirectToSlash: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], (err) => { | ||
expect(err).to.not.exist(); | ||
someServer.inject({ | ||
method: 'get', | ||
url: '/' | ||
}, (res) => { | ||
expect(res.statusCode).to.be.equal(404); | ||
expect(res.result).to.equal({ | ||
statusCode: 404, | ||
error: 'Not Found' | ||
}); | ||
someServer.inject({ | ||
method: 'get', | ||
url: '/test' | ||
}, (res) => { | ||
expect(res.statusCode).to.be.equal(302); | ||
expect(res.result).to.not.exist(); | ||
someServer.inject({ | ||
method: 'get', | ||
url: '/error' | ||
}, (res) => { | ||
expect(res.statusCode).to.be.equal(404); | ||
expect(res.result).to.equal({ | ||
statusCode: 404, | ||
error: 'Not Found' | ||
}); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17197
254
76