gpt4 book ai didi

node.js - Heroku Node js错误: 'Internal Server Error'

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:28 27 4
gpt4 key购买 nike

我已经在本地主机上创建了我的第一个 Node js 应用程序:)它是一个 API,并且可以在本地主机上完美运行:我在地址栏上输入“http://localhost:8080/home?star=3333 ”并得到:

{"Bezeq":"תפוס","Hot":"תפוס","Cellcom":"לא פנויה","Partner":"תפוס"}

(它做了它应该做的事情)

我将我的文件夹部署到 Heroku,在遇到一些问题后,我成功地完成了它。我制作了一个 Procfile(我观看了一个教程,说这是必要的......)并将我的端口号更改为 process.env.PORT
一切结束后,我以为我已经完成了,但不幸的是事实并非如此。
当尝试在“https://my-app-name.herokuapp.com/home?number=3333”打开我的应用程序时,我收到以下消息:内部服务器错误
我的日志:


2019-07-04T09:41:24.651145+00:00 app[web.1]: TypeError: Cannot read property 'toString' of undefined
2019-07-04T09:41:24.651168+00:00 app[web.1]: at /app/MainAPI.js:7:35
2019-07-04T09:41:24.651171+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-07-04T09:41:24.651172+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2019-07-04T09:41:24.651173+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2019-07-04T09:41:24.651174+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-07-04T09:41:24.651176+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:281:22
2019-07-04T09:41:24.651177+00:00 app[web.1]: at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
2019-07-04T09:41:24.651177+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/index.js:275:10)
2019-07-04T09:41:24.651179+00:00 app[web.1]: at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
2019-07-04T09:41:24.651179+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-07-04T09:41:24.649937+00:00 heroku[router]: at=info method=GET path="/home?number=3333" host=star-status.herokuapp.com request_id=b1b9b421-92bf-4394-a076-4a2d1056c805 fwd="216.72.40.6" dyno=web.1 connect=1ms service=2ms status=500 bytes=404 protocol=https

包.json:

{
"name": "my-app-name",
"version": "1.0.0",
"description": "",
"main": "MainAPI.js",
"dependencies": {
"express": "^4.17.1",
"table-scraper": "^0.1.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

MainAPI.js:

const http = require('http');
const express = require('express');
var app = express();

app.listen(process.env.PORT || 8080);
app.get('/home', function (req, res) {
getStarsStatus(req.query.star.toString(),()=>{
res.end(JSON.stringify(statuses));
});
});

var statuses = {
'Bezeq': '',
'Hot': '',
'Cellcom': '',
'Partner': ''
};

function getStarsStatus(star, callback) {

let numStatusesFetched = 0;
require('./Bezeq').GetStarStatus(star, function(status) {
statuses['Bezeq'] = status;
numStatusesFetched++;
if(numStatusesFetched == 4) callback();
});

require('./Hot').GetStarStatus(star, function(status){
statuses['Hot'] = status[0][0]['סטטוס'];
numStatusesFetched++;
if(numStatusesFetched == 4) callback();
});

require('./Partner').GetStarStatus(star, function(status) {
statuses['Partner'] = status;
numStatusesFetched++;
if(numStatusesFetched == 4) callback();

});

require('./Cellcom').GetStarStatus(star, function(status) {
statuses['Cellcom'] = status;
numStatusesFetched++;
if(numStatusesFetched == 4) callback();
});

}

有人知道为什么它不起作用吗?
谢谢!

最佳答案

天哪,我太笨了..
我输入了 number=3333 而不是 star=3333..
谢谢大家

关于node.js - Heroku Node js错误: 'Internal Server Error' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56884518/

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