无法在插件 HapiJS 中添加模板引擎
Can't add templating engine in plugin HapiJS
我想为每个插件实现路由,但我无法在插件中添加视图引擎。我见过这样的例子,例如:https://github.com/hapijs-edge/hapi-plugins.com/blob/master/lib/routes.js,但我收到一条错误消息 server.views is not a function
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);
});
我想为每个插件实现路由,但我无法在插件中添加视图引擎。我见过这样的例子,例如:https://github.com/hapijs-edge/hapi-plugins.com/blob/master/lib/routes.js,但我收到一条错误消息 server.views is not a function
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);
});