I am new to the node.js. I am trying to setup the client server connection using unix socket, where my client request would be in node.js and server running in the background would be in go.
Client side Code:
var request = require('request');
request('http://unix:/tmp/static0.sock:/volumes/list', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
} else {
console.log("In else part of the receiver" + response.statusCode + body)
}
}
})
When I try to communicate with the server written in go it is shows the HTTP error: 400 Bad Request: malformed Host header'
The same works with:
curl -X GET --unix-socket /tmp/static0.sock http://:/volumes/list
Not sure what is wrong with my request. Do we need to send the headers? I expecting the JSON response.
To accomplish this without using the request module, try the following:
const http = require('http');
const options = {
socketPath: '/tmp/static0.sock',
path: '/volumes/list',
};
const callback = res => {
console.log(`STATUS: ${res.statusCode}`);
res.setEncoding('utf8');
res.on('data', data => console.log(data));
res.on('error', data => console.error(data));
};
const clientRequest = http.request(options, callback);
clientRequest.end();