【发布时间】:2016-09-28 02:49:03
【问题描述】:
我发现遵循 hapijs-react-views 包设置指南 (npm hapi-js-react-views) 时遇到了一些困难。
我可以运行服务器,但我只在 localhost:3000 上收到此错误
{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}
我在 github 上的 repo 是:hapi-react GitHub
我的代码是:
-routes
--index.js
-views
--index.jsx
-app.js
-package.js
// 路由/index.js
exports.index = function(request, reply){
reply.view('index', { name: 'John' });
};
//views/index.js
var HelloMessage = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
module.exports = HelloMessage;
//app.js
var hapi = require('hapi');
var vision = require('vision');
var path = require('path');
var engine = require('hapijs-react-views')();
// Create a server with a host and port
var server = new hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
// Register Hapi plugins
server.register(vision, function (err) {
if(err) throw err;
});
var options = { jsx: { harmony: true } };
server.views({
defaultExtension: 'jsx',
engines: {
jsx: require('hapijs-react-views')(options), // support for .jsx files
js: require('hapijs-react-views')(options) // support for .js
},
relativeTo: __dirname,
path: 'views'
});
// Add the route
server.route({
method: 'GET',
path: '/',
config: {
handler: require('./routes').index
}
});
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
//package.json
"dependencies": {
"hapi": "^13.4.1",
"hapijs-react-views": "^0.7.3",
"react": "^15.1.0",
"vision": "^4.1.0"
}
你能帮帮我吗? 提前致谢。
【问题讨论】:
-
您遇到内部服务器错误。为什么无法分辨,因为您没有提供足够的代码/信息。可能有 1000 个不同的原因。
-
你可以在 github repo 中看到我所有的代码。你喜欢我把它贴在这里吗?
-
是的,请尽可能在帖子中提供代码。不过不要发布您的整个项目,只发布您认为与您的问题相关的部分。
-
好的,谢谢。我已经添加了代码。