literallypenguin
literallypenguin

Reputation: 121

Node.js REST with Sockets

The problem I am trying to solve is

I can communicate to the client via REST and separately I can communicate to the external server via socket (response time is ~100ms). But combining these results yields nothing.

const sjsc = require('sockjs-client');
app.post('/form', function(req, res) {
    const srvc = sjsc('http://external.server:port/path');
    srvc.onopen = function () {
        srvc.send(testData);
    }

    srvc.onmessage = function(data) {
        console.log('received ', data);
        res.send(data);
    };
});

Upvotes: 2

Views: 331

Answers (1)

literallypenguin
literallypenguin

Reputation: 121

const srvc = sjsc('http://external.server:port/path');

this needed to be a let. this is the only thing i changed and works perfectly.

let srvc = sjsc('http://external.server:port/path');

Upvotes: 1

Related Questions