Request to https://127.0.0.1:9080/auth failed, reason: socket hang up


#1

am new to node but I follow the documneation to create a simple Node.js app that listen to Realm changes.

the problem is that , when I start the app using npm start, i am getting the following error

UnhandledPromiseRejectionWarning: FetchError: request to https://XX.XX.XX.XX:9080/auth failed, reason: socket hang up
    at ClientRequest.<anonymous> (/home/alkhamisah/CMTRealm/RealmChangeListener/node_modules/node-fetch/index.js:133:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:105571) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:105571) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I tried different ip addresses for the server which is installed in the same virtual machine in Azure.
0.0.0.0:9080
127.0.0.1:9080
actual IP address of the server:9080

I also tried different users including the default admin: realm-admin
Here is the index.js file:

'use strict';
var Realm = require('realm');

// the URL to the Realm Object Server
var SERVER_URL = '//XX.XX.XX.XX:9080';

var NOTIFIER_PATH = '^/CMT';

//declare admin user
let adminUser = undefined

var handleChange = async function (changeEvent) {

  var realm = changeEvent.realm;
  var CrisisDB = realm.objects('CrisisDB');
  var crisisIndexes = changeEvent.changes.CrisisDB.insertions;

          for (let crisisIndexe of crisisIndexes) {
    var coupon = CrisisDB[crisisIndexe];
    var crisis = CrisisDB[crisisIndexe];
    if (crisis.Subject !== "no change") {
      // Attention: Writes here will trigger a subsequent notification.
      // Take care that this doesn't cause infinite changes!
      realm.write(function() {
                  crisis.subject = "changed by listener";
      });
    }
  }
}

// register the event handler callback
async function main() {
    adminUser = await Realm.Sync.User.login(`https:${SERVER_URL}`, 'Ali', '123')
 Realm.Sync.addListener(`realms:${SERVER_URL}`, adminUser, NOTIFIER_PATH, 'change', handleChange);
}

main()

Is there a port that I need to open or any extra settings that I missed?


#3

I think this is connect to the issue that I ignored earlier thinking that it was avoidable.

when I installed ROS and created a Realm, I didn’t get any set up page. I just used the default password of the realm-admin to access the Realm Studio.

even when I go to: 127.0.0.1:9080 , all what I get is a simple page with links to the manual and to download Realm Studio. I can’t access the setup or login page on the browser.

that is why when I call 127.0.0.1:9080/auth , I am not getting the proper response.

Even though, Realm is working fine and I am able to access it with the mobile app and Realm Studio.

I am currently stuck and any help will be highly appreciated.


#4

I tested on Realm Cloud and it’s working as expected.
I didn’t change anything but the IP address.

What should I do to make it work on a self-hosted version?


#5

If you haven’t set up SSL certificates for the self hosted version, you should use http://server-address:9080 instead of https://. Similarly, you should use realm:// instead of realms://.


#6

Hi @nirinchev and sorry for the late response.
After doing what you suggested, I am still facing an error while trying to run the node js Listener program.

ERROR: Connection[1]: Failed to connect to endpoint '127.0.0.1:80': Connection refused
ERROR: Connection[1]: Failed to connect to '127.0.0.1:80': All endpoints failed
(node:21206) UnhandledPromiseRejectionWarning: Connection refused

I am not sure why does the listener tries to access the server at port 80 while Realm server is accessible at 8080.

This is what I updated from the original file

 adminUser = await Realm.Sync.User.login('http://127.0.0.1:9080', 'realm-admin', '')
 Realm.Sync.addListener('realm://127.0.0.1', adminUser, NOTIFIER_PATH, 'change', handleChange);

Realm server is in the same Virtual Machine as this node project so 127.0.0.1:9080 is accessible even in the web browser. Port 80 is allowing inbound and outbound connections.

The issue is that, I can’t access 127.0.0.1:80 on the browser, so the error make sense. But why does the listener want to go there anyway?


#8

It goes there because you’ve specified its address as 'realm://127.0.0.1'. Since your ROS instance is listening to 9080, you need to specify the port as well: 'realm://127.0.0.1:9080'.