【问题标题】:Heroku node js Error: 'Internal Server Error'Heroku 节点 js 错误:“内部服务器错误”
【发布时间】:2023-03-10 21:37:02
【问题描述】:

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

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

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

我将我的文件夹部署到 Heroku,在遇到一些问题后,我成功地做到了。我制作了一个 Procfile(我观看了一个说这是必要的教程......)并将我的端口号更改为 process.env.PORT
毕竟,我以为我已经完成了,但不幸的是事实并非如此。
当试图在“https://my-app-name.herokuapp.com/home?number=3333”打开我的应用程序时,我得到了这个:Internal Server Error
我的日志:


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();
    });

}

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

【问题讨论】:

  • 更多日志好吗?在您发布之前,应该有一些解释您的错误
  • 这就是我所拥有的...如果我错了请纠正我:Heroku > my-app-name > more > 查看日志
  • 正确,下拉菜单中的“所有进程”。日志可以滚动吗?
  • 请在您的应用程序文件夹中使用heroku logs 或将 PaperTrail 插件添加到 Heroku 上的应用程序(免费)以查看完整日志并将其粘贴到此处。
  • 您能否分享package.jsonserver start 的conde 截图(可能是index.jsserver.js)。

标签: node.js heroku


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多