Custom database error "connect ECONNREFUSED"

Problem statement

We are trying to set up a Custom Database connection and believe we have created the login script correctly. But, when testing the login, we see the "connect ECONNREFUSED 127.0.0.1:443" error on the login page.

Troubleshooting

  • Custom Database Login script:
function login(email, password, callback) {
  const request = require('request');

  request.get({
    url: 'https://localhost/profile';,
    auth: {
      username: email,
      password: password
    }
  }, function(err, response, body) {
    if (err) return callback(err);
    if (response.statusCode === 401) return callback();
    const user = JSON.parse(body);

    callback(null, {
      user_id: user.user_id.toString(),
      nickname: user.nickname,
      email: user.email
    });
  });
}

Cause

  • The script is attempting to request ‘https://localhost/profile’;. However, database action scripts run on Webtask containers that do not have access to a server running locally on your machine.

Solution

We recommend making the database accessible on a public URL and changing the localhost URL to a publicly accessible URL.