有人在Nodewebkit中运行Hapi应用程序吗?
这是我的package.json:
{
"name": "nw",
"version": "1.0.0",
"description": "",
"main": "index.html",
"node-main": "nwindex.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"webkit": {
"page-cache":false
},
"author": "",
"window": {
"toolbar": true,
"width": 800,
"height": 500
},
"license": "ISC",
"dependencies": {
"jquery": "^2.1.4",
"nw": "^0.12.2",
"pretty-bytes": "^1.0.2"
}
}
这是我的index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My App</title>
</head>
<body>
<script type="text/javascript">
var gui = require('nw.gui');
var win = gui.Window.get();
var fs = require("fs");
gui.App.clearCache();
setTimeout (function () {
window.location = 'http://localhost:3000';
},1000)
这是我的nwindex。js语言(
Getting started from official site
):
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 3000 });
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Hello, world!');
}
});
server.route({
method: 'GET',
path: '/{name}',
handler: function (request, reply) {
reply('Hello, ' + encodeURIComponent(request.params.name) + '!');
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
问题是,当我启动NW时,它立即存在。我能看到里面发生了什么。
我逐行删除了代码,以查看问题所在,并将其缩小到初始调用行:
const Hapi = require('hapi');
这似乎会使应用程序崩溃。任何帮助都是感激的。
我使用的Nodewebkit版本:
-
西北部。js版本0.12.3
-
io。js版本1.2.0
-
铬41.0.2272.76
经过更多的测试,似乎出现了问题:
server.start((err) => {
这=>操作人员如何绕过它?