Just tried updating to the latest version of Hapi.js but getting error for directory
handler ...
We are using hapi.js to serve a directory
in our static-server.js see: https://github.com/dwyl/learn-tdd/blob/5b132bfe5e1787b684ff44eadaf8b53438449323/static-server.js#L3
The directory
handler worked fine in hapi 8.x but in 9.0.1 we get the error:
Error: Unknown handler: directory
We've tried searching on the Hapi.js Route API: http://hapijs.com/api#route-handler but have not found the directory
handler ... was it removed in the latest release? The "old" version of Hapi.js had: http://hapijs.com/api/8.8.1#route-handler
full stack trace: https://github.com/dwyl/learn-tdd/issues/22
The inert plugin needs to be included manually in version 9 (release notes: https://github.com/hapijs/hapi/issues/2682 ). Add it as a plugin using server.register
follow the instructions on https://www.npmjs.com/package/inert#examples eg:
var Hapi = require('hapi');
var Inert = require('inert');
var Path = require('path');
var server = new Hapi.Server();
var port = process.env.PORT || 8000;
server.register(Inert, function () {
server.connection({ port: port });
server.route( {
method: 'GET',
path: '/{param*}',
handler: {
directory: { path: Path.normalize(__dirname + '/') }
}
});
server.start(function() { console.log('Visit: http://127.0.0.1:' +port) });
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.