gpt4 book ai didi

node.js - Hapijs-react-views 设置

转载 作者:太空宇宙 更新时间:2023-11-04 00:39:21 24 4
gpt4 key购买 nike

我发现按照 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"
}

你能帮我吗?提前致谢。

最佳答案

对于将来看到这一点的任何人,这里有一个使用 vision 渲染 jsx 的工作示例:https://github.com/hapijs/vision/tree/master/examples/jsx

关于node.js - Hapijs-react-views 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37522850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com