我想实现每个插件的路由,但我无法在插件中添加视图引擎。我见过的例子在那里,这是可能的,例如:https://github.com/hapijs-edge/hapi-plugins.com/blob/master/lib/routes.js,但我得到一个错误说server.views is not a function
无法在插件中添加模板引擎HapiJS
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection();
var myPlugin = {
register: function (server, options, next) {
// Error happens here, should be able to see server.views()
console.log(server.views());
next();
}
};
myPlugin.register.attributes = {
name: 'myPlugin',
version: '1.0.0'
};
server.register(myPlugin, function(err) {
if (err) {
console.error('Failed to load a plugin:', err);
}
});
server.start(function() {
console.log('Server running at:', server.info.uri);
});
你能说明一下如何或为什么要改善这个答案的质量和价值吗? –