简体   繁体   中英

Heroku Node deployment “internal server error”

I have my app deployed to heroku. Once I go to the user signup page and enter my credentials the site immediately crashes, displaying internal server error in the browser, and giving me this in the heroku logs .

I'm not sure what might be the issue so I don't know which code to give? I don't think it has to do with MySQL but considering it's mentioned in the error report, it might be? Either way here is my connection.js :

const mysql = require('mysql');
let connection;

if (process.env.JAWSDB_URL) {
    connection = mysql.createConnection(process.env.JAWSDB_URL);
} else {
    connection = mysql.createConnection({
        host: 'localhost',
        port: 3306,
        user: 'root',
        password: '',
        database: 'trythis_db'
    });
};

connection.connect(function(err) {
    if (err) {
        console.log(err);
    } else {
        console.log('mysql is connected');
    };
});


module.exports = connection;

This is my error code:

2017-12-04T04:58:51.486756+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:3306
2017-12-04T04:58:51.486150+00:00 app[web.1]: POST /signup 302 287.664 ms - 46
2017-12-04T04:58:51.486758+00:00 app[web.1]:     at Object._errnoException (util.js:1024:11)
2017-12-04T04:58:51.486758+00:00 app[web.1]:     at _exceptionWithHostPort (util.js:1046:20)
2017-12-04T04:58:51.486759+00:00 app[web.1]:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
2017-12-04T04:58:51.486760+00:00 app[web.1]:     --------------------
2017-12-04T04:58:51.486761+00:00 app[web.1]:     at Protocol._enqueue (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2017-12-04T04:58:51.486762+00:00 app[web.1]:     at Protocol.handshake (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:52:23)
2017-12-04T04:58:51.486763+00:00 app[web.1]:     at PoolConnection.connect (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Connection.js:130:18)
2017-12-04T04:58:51.486763+00:00 app[web.1]:     at Pool.getConnection (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:48:16)
2017-12-04T04:58:51.486764+00:00 app[web.1]:     at Pool.query (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:202:8)
2017-12-04T04:58:51.486765+00:00 app[web.1]:     at MySQLStore.set (/app/node_modules/express-mysql-session/lib/index.js:192:19)
2017-12-04T04:58:51.486766+00:00 app[web.1]:     at Session.save (/app/node_modules/express-session/session/session.js:72:25)
2017-12-04T04:58:51.486766+00:00 app[web.1]:     at Session.save (/app/node_modules/express-session/index.js:381:15)
2017-12-04T04:58:51.486767+00:00 app[web.1]:     at ServerResponse.end (/app/node_modules/express-session/index.js:330:21)
2017-12-04T04:58:51.486768+00:00 app[web.1]:     at ServerResponse.redirect (/app/node_modules/express/lib/response.js:947:10)
2017-12-04T04:58:51.638706+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:3306
2017-12-04T04:58:51.638708+00:00 app[web.1]:     at Object._errnoException (util.js:1024:11)
2017-12-04T04:58:51.638709+00:00 app[web.1]:     at _exceptionWithHostPort (util.js:1046:20)
2017-12-04T04:58:51.638710+00:00 app[web.1]:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
2017-12-04T04:58:51.638710+00:00 app[web.1]:     --------------------
2017-12-04T04:58:51.638711+00:00 app[web.1]:     at Protocol._enqueue (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2017-12-04T04:58:51.638712+00:00 app[web.1]:     at Protocol.handshake (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:52:23)
2017-12-04T04:58:51.638713+00:00 app[web.1]:     at PoolConnection.connect (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Connection.js:130:18)
2017-12-04T04:58:51.638713+00:00 app[web.1]:     at Pool.getConnection (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:48:16)
2017-12-04T04:58:51.638714+00:00 app[web.1]:     at Pool.query (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:202:8)
2017-12-04T04:58:51.638802+00:00 app[web.1]:     at session (/app/node_modules/express-session/index.js:460:11)
2017-12-04T04:58:51.638800+00:00 app[web.1]:     at MySQLStore.get (/app/node_modules/express-mysql-session/lib/index.js:130:19)
2017-12-04T04:58:51.638803+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-12-04T04:58:51.638804+00:00 app[web.1]:     at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
2017-12-04T04:58:51.638804+00:00 app[web.1]:     at /app/node_modules/express/lib/router/index.js:284:7

The first line of the error ( Error: connect ECONNREFUSED 127.0.0.1:3306 ) says that the app is trying to connect to localhost even when it is hosted online, where it should try to connect to the online database. You need to figure out what's wrong in the if-else statements, since, the else loop is being executed, which, I guess, is for your local environment.

Make sure you have added JAWSDB_URL under project config variables.

(Heroku project -> settings -> config variables -> reveal variables -> your var )

问题是另一个与在MySQL中存储会话有关的库...

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