EconnRefused Heroku Trailhead快速入门:Heroku Connect更改并重新部署应用程序

时间:2018-10-03 21:48:36

标签: heroku salesforce heroku-connect

通过Heroku Connect上的salesforce线索工作。一切都完成了,直到“更改并重新部署应用程序”步骤为止。停止应用程序并修改server.js文件后,我无法连接/更新数据库记录。恢复了server.js文件,同样的问题。我在Windows 7,npm --version = 4.6.1,节点--version = v8.11.1,git --version = 2.14.2.windows.2。任何想法都可能导致以下错误:

{ 
    Error: connect ECONNREFUSED 127.0.0.1:5432
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 5432 
}  

谢谢!

以下是设置/启动应用程序的命令:

SET DATABASE_URL=`heroku config:get DATABASE_URL`
SET PGSSLMODE=require
npm start    

这是server.js文件的内容:

var express = require('express');
var bodyParser = require('body-parser');
var pg = require('pg');

var app = express();

app.set('port', process.env.PORT || 5000);

app.use(express.static('public'));
app.use(bodyParser.json());

app.post('/update', function(req, res) {
    pg.connect(process.env.DATABASE_URL, function (err, conn, done) {
        // watch for any connect issues
        if (err) console.log(err);
        conn.query(
            'UPDATE salesforce.Contact SET Phone = $1, MobilePhone = $1 WHERE LOWER(FirstName) = LOWER($2) AND LOWER(LastName) = LOWER($3) AND 
LOWER(Email) = LOWER($4)',
            [req.body.phone.trim(), req.body.firstName.trim(), 
req.body.lastName.trim(), req.body.email.trim()],
            function(err, result) {
                if (err != null || result.rowCount == 0) {
                  conn.query('INSERT INTO salesforce.Contact (Phone, 
MobilePhone, FirstName, LastName, Email) VALUES ($1, $2, $3, $4, $5)',
                  [req.body.phone.trim(), req.body.phone.trim(), 
req.body.firstName.trim(), req.body.lastName.trim(), 
req.body.email.trim()],
                  function(err, result) {
                    done();
                    if (err) {
                        res.status(400).json({error: err.message});
                    }
                    else {
                        // this will still cause jquery to display 'Record 
updated!'
                        // eventhough it was inserted
                        res.json(result);
                    }
                  });
                }
                else {
                    done();
                    res.json(result);
                }
            }
        );
    });
});

app.listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
});

1 个答案:

答案 0 :(得分:1)

您正在尝试连接到需要连接到Heroku Postgres实例的本地数据库(Pub.build(); )。 This is the relevant config来自应用程序代码。确保server.js正在连接到Heroku代表您管理的127.0.0.1