I am working on a project that has a mobile appplication, and two web servers(let it be named tub and cloud). THe web servers are developed in node.js environment.
The mobile app will request for some information from the web server named 'tub' ;
this 'tub' will in turn act as a http client and request some information from the web server named 'cloud'.
When the 'tub' requests the 'cloud', the 'cloud' has to process the incoming request and then has to do header redirection to another url(possibly in the 'cloud' or some other server) and return the response back to the 'tub'.
I am facing certain difficulty in figuring out header redirection in the 'cloud' server. Below I have mentioned the coding for putting a rest api call from 'tub' to 'cloud' :
var options =
{
hostname: '10.0.0.1',
port: 1048,
path: '/api/v1/vendor?DevType=mobile,
method: 'GET',
headers:
{
'Content-Type': 'application/x-www-form-urlencoded'
}
};
var request = http.request(options, function(cloudres)
{
cloudres.setEncoding('utf8');
cloudres.on('data', function (chunk)
{
console.log("chunk");
console.log(chunk);
});
});
request.on('error', function(e)
{
console.log('Cloud Package http Request Error : ' + e.message);
});
request.end();
Below mentioned code is in the 'cloud' server for header redirection :
var express = require('express');
var http = require('http');
var app = express(); // Create an Express instance.
var httpserver = http.createServer(app); // Create a http server and hook the Express instance to it.
httpserver.listen(1048,function() // Make the http server listen to a port.
{
console.log("Http Server Listening On Port : 1048");
});
app.get('/api/v1/vendor',function(req,res)
{
res.statusCode = 302;
res.setHeader('Content-Disposition', 'attachment');
res.setHeader('Location', 'http://10.0.0.1:80/mobilelib.zip');
res.end();
});
I am not getting neither any response nor any error in the 'tub' . Am I going wrong anywhere ? How can we track whether header redirection is taking place or not.