Handling HTTP requests with for different ports

171 views
Skip to first unread message

Sandeep Bhat

unread,
Aug 7, 2016, 5:57:56 PM8/7/16
to nodejs
Hi All

I am trying to develop a Full Stack App using MEAN stack along with ionic framework for the front end. As such I am not able to run the server on the same port as the ionic as it by default takes up a port(8100). So the server running at port 3000 for example has to respond to a GET request made from port 8100.

var req = {
      method: 'GET',
      url: 'http://localhost:3000/test/'+id
    };
    $http(req).success(function(response){
      console.log("test sucesssful");
    });

I am not able to see the above "test successful" log in my browser though the server accepts the GET request and the response header is 200. When I use POSTMAN to test it I see the response body too but not in the browser.

Server snippet --

app.get("/test/:id",function(req,res){
  console.log("Got a request");
  var id = req.params.id;
  res.send("Got your request:");
  console.log(id);
});

All the logs as done in console.log() calls work. It's just that the response is not seen in the browser but can be seen when tried with POSTMAN.
I am a beginner fiddling with MEAN stack. Thanks for assistance in advance.

Sergey Jamy

unread,
Aug 8, 2016, 2:15:13 AM8/8/16
to nodejs
Hi! Other port is like other domain. You should setup CORS to resolve this issue. But I would advise to work with one port and setup proxy in node from 8100 to 3000
Reply all
Reply to author
Forward
0 new messages