gpt4 book ai didi

node.js - 502 错误网关 nginx 谷歌应用程序引擎

转载 作者:太空宇宙 更新时间:2023-11-04 01:58:14 25 4
gpt4 key购买 nike

我正在使用 Express 构建 NodeJS 应用程序,这是我的代码:

var express = require('express');
var app = express();
var session = require('express-session');
var uuidv1 = require('uuid/v1');
require('dotenv').config();

var APIAI_TOKEN = process.env.APIAI_TOKEN;
var APIAI_SESSION_ID = uuidv1();

app.use(express.static(__dirname + '/views')); // html
app.use(express.static(__dirname + '/public')); // js, css, images

var server = require('http').createServer(app);
var port = process.env.port || 3000;

server.listen(port, function() {
console.log('Server listening at port: ', port);
// console.log(APIAI_SESSION_ID);
// console.log(APIAI_TOKEN);
});

app.use(session({
genid: function(req) {
return APIAI_SESSION_ID;
},
secret: 'secret',
saveUninitialized: true,
resave: true
}));

var io = require('socket.io')(server);

var apiai = require('apiai')(APIAI_TOKEN);
var rp = require('request-promise');

//#region Web UI

app.get('/', function(req, res) {
res.sendFile('index.html');
});

我使用 Node 应用程序启动我的应用程序,一切都在我的本地主机上完美运行,但是当我将应用程序部署到 Google App 引擎时,我收到 502 错误网关错误,当我检查日志时,它发生在 app.get() 方法中。我什至也将其部署到 Heroku 服务器,该应用程序在同一点崩溃。我的代码可能有什么问题?这是 Heroku 服务器的日志:

2017-11-01T16:35:57.528020+00:00 heroku[router]: at=error code=H10 

desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=d956df30-8352-4a54-80e6-2aa1fc96276b fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:58.138751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=96b2bf0d-df05-4d7e-9018-0b09e1dfa748 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-11-01T16:19:36.517868+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-11-01T16:19:36.513572+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-11-01T16:19:36.517927+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-11-01T16:19:36.584087+00:00 heroku[web.1]: Process exited with status 1
2017-11-01T16:19:36.607609+00:00 heroku[web.1]: State changed from starting to crashed
2017-11-01T16:20:47.248202+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=41e9f39b-e908-4cee-a430-0d7f44a17590 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:20:47.891459+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=9f244daf-7a3e-405e-b445-2fadd8b2735b fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:13.187594+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=455ccd5e-e389-49be-b892-e5e222c9864f fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:13.805998+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=112a5f08-632e-463d-b8e8-ed6de13b3596 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:57.528020+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=d956df30-8352-4a54-80e6-2aa1fc96276b fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:58.138751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=96b2bf0d-df05-4d7e-9018-0b09e1dfa748 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https

最佳答案

不确定 Heroku,但对于 App Engine,将端口更改为 8080 是否有效?

例如:

const server = app.listen(8080, () => {
const host = server.address().address;
const port = server.address().port;

console.log(`Example app listening at http://${host}:${port}`);
});

来自Run Express.js on Google App Engine Flexible Environment

关于node.js - 502 错误网关 nginx 谷歌应用程序引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47059020/

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