简体   繁体   中英

Heroku node js Error: 'Internal Server Error'

I've made my first node js application on localhost :) It's an API, and it works perfectly on localhost: I typed " http://localhost:8080/home?star=3333 " on address bar and got:

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

(It does what It's supposed to do)

I deployed my folder to Heroku and after some problems, I've managed to do it successfully. I've made a Procfile (I watch a tutorial that said it's necessary...) and changed my port number to process.env.PORT .
After all that, I thought I'm done, but unfortunately that is not the case.
When trying to open my app at " https://my-app-name.herokuapp.com/home?number=3333 " I get this: Internal Server Error .
My logs:


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

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

}

Does someone have an idea for why it doesn't work?
Thank You!

OMG, I'm so stupid..
I typed number=3333 instead of star=3333 ..
Thank You Everybody

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM