Javascript 节点hapi应用程序启动,但似乎未绑定到端口
我有一个正在开发的hapi应用程序。在使用Procfile运行我通常的node foreman时,应用程序在命令行中加载,没有错误,但是在浏览到配置的端口时,页面错误、没有连接,或者特别是连接被拒绝。返回CLI,没有错误。来自服务器的简单消息。开始“服务器正在运行” 我试着直接用gulp启动(没有错误)。没有浏览器访问权限 我尝试使用node直接启动(没有错误)。没有浏览器访问权限 我尝试用hapi和express创建一个hello world应用程序,两个应用程序都没有错误,并在浏览器中加载 我甚至将代码版本控制回我知道有效的版本。从CLI正常启动服务器,但无浏览器加载/访问 我有点困了,我很想知道下一步该怎么解决问题 先谢谢你 以下是应用程序JS:Javascript 节点hapi应用程序启动,但似乎未绑定到端口,javascript,node.js,hapijs,Javascript,Node.js,Hapijs,我有一个正在开发的hapi应用程序。在使用Procfile运行我通常的node foreman时,应用程序在命令行中加载,没有错误,但是在浏览到配置的端口时,页面错误、没有连接,或者特别是连接被拒绝。返回CLI,没有错误。来自服务器的简单消息。开始“服务器正在运行” 我试着直接用gulp启动(没有错误)。没有浏览器访问权限 我尝试使用node直接启动(没有错误)。没有浏览器访问权限 我尝试用hapi和express创建一个hello world应用程序,两个应用程序都没有错误,并在浏览器中加载
var config = require('./config');
hapi = require('../lib/hapi'),
chalk = require('chalk'),
module.exports.init = function (callback) {
//init app bserver
server = hapi.init();
callback(server, config );
};
module.exports.start = function (callback) {
var _this = this;
_this.init(function (server, config) {
// Start the app by listening on <port>
server.start(function () {
// Logging initialization
console.log('+-----------------------------------------------------------+');
console.log(chalk.green('| ' + config.app.title+ '\t\t\t|'));
console.log('+-----------------------------------------------------------+');
console.log(chalk.green('| Environment:\t' + process.env.NODE_ENV));
console.log(chalk.green('| Standard Port:\t' + config.port));
if (config.https.ssl === true ) {
console.log(chalk.green('| Secure Port:\t' + config.https.port));
console.log(chalk.green('| HTTPs:\t\ton'));
}
console.log(chalk.green('| App version:\t' + config.version));
console.log(chalk.green('| App url:\t\t' + ((config.https.ssl === true ? 'https' : 'http')+"://"+config.url)));
console.log('+-----------------------------------------------------------+');
console.log('| Database Configuration\t\t\t\t\t|');
console.log('+-----------------------------------------------------------+');
console.log(chalk.green(JSON.stringify(config.db, null, 4)));
console.log('+-----------------------------------------------------------+');
if (callback) callback(server, db, config);
});
return server;
});
};
以下是CLI输出:
[13:58:31] [nodemon] starting `node --inspect server.js`
[13:58:31] [nodemon] child pid: 5596
Debugger listening on ws://127.0.0.1:9229/e2f5837f-b552-4156-b004-e7adb3d30d05
For help see https://nodejs.org/en/docs/inspector
+-----------------------------------------------------------+
| APP - Development Environment |
+-----------------------------------------------------------+
| Environment: development
| Standard Port: 3000
| Secure Port: 3001
| HTTPs: on
| App version: 0.3.0
| App url: https://localhost:3001
+-----------------------------------------------------------+
| Database Configuration |
+-----------------------------------------------------------+
{
"client": "postgresql",
"connection": {
"host": "localhost",
"port": "5432",
"database": "database",
"user": "user",
"password": "password",
"ssl": true
},
"pool": {
"min": 2,
"max": 10
},
"migrations": {
"tableName": "knex_migrations"
},
"debug": true
}
+-----------------------------------------------------------+
嗯。我找到了答案(这是一周两次,看不清细节——真丢脸)
导致我出现更大问题的较小问题是在服务器上。启动(回调)我没有进行任何错误检查,类似于:
server.start(function(err) {
if(err) {
throw err;
}
});
一旦我添加了错误日志,它就暴露了服务器悄悄失败的原因
我的Hapi配置需要一个memcached模块,而且我还没有在本地启动memcached服务器
全部恢复正常工作:)正常。我找到了答案(这是一周两次,看不清细节——真丢脸)
导致我出现更大问题的较小问题是在服务器上。启动(回调)我没有进行任何错误检查,类似于:
server.start(function(err) {
if(err) {
throw err;
}
});
一旦我添加了错误日志,它就暴露了服务器悄悄失败的原因
我的Hapi配置需要一个memcached模块,而且我还没有在本地启动memcached服务器
全部返回到按设计工作:)请向我们显示您的app.js代码。@alexmac我在上面添加了代码。谢谢。请给我们看你的app.js代码。@alexmac我在上面添加了代码。非常感谢。