我发现有些困难要遵循hapijs-react-views包设置指南(npm hapi-js-react-views)。
我可以运行服务器,但我只在localhost:3000
上收到此错误{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}
我在github上的回购是:hapi-react GitHub
我的代码是:
-routes
--index.js
-views
--index.jsx
-app.js
-package.js
// routes / 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"
}
你能帮帮我吗?
提前谢谢。
答案 0 :(得分:1)
对于将来会看到此内容的任何人,都会在jsx
处使用vision
呈现mylist <- list(A1=c("D2", "E2", "F2", "H2"),
B1=c("G2", "I2", "J2", "K2", "L2"),
C1=c("J2", "M2", "N2", "O2", "P2", "Q2", "R2", "S2"))
mydf <- lapply(1:length(mylist), function(i) {
data.frame(`Female ID`=names(mylist)[i], `Mate ID`=mylist[[i]], stringsAsFactors=F, check.names=F)
})
mydf <- do.call(rbind, mydf)
的实际示例:https://github.com/hapijs/vision/tree/master/examples/jsx
答案 1 :(得分:0)
我遇到了这个问题。文档没有说明,但您仍然需要在视图文件中使用React。这解决了我的问题。