Friday 9 June 2017

Websocket not respond after API call

I create a proxy that connect webhook to local with Web Socket.

In client i use Websocket and on data send the same call in local server with same payload:

client.on('data', function (data) {
    try {
        const date = new Date();
        console.log(date.toISOString() + " :: Message from server");
        apiCall(data);
    }
    catch (err) {
        console.log("ERROR " + err);
    }
});

const apiCall = (message) => {
    const uri = `http://pathurl`;
    request({
        method: 'POST',
        uri: uri,
        json: JSON.parse(message),
        headers: { 'Content-Type':'application/json'}
    }, function (error, response, body) {
        if (error) {
            return console.error('upload failed:', error);
        }
        console.log('Upload successful!  Server responded with:', body);
    });
};

In first time, the server respond Ok. After, the socket not receive no data and the client not responde.



via Pasalino

No comments:

Post a Comment