Get Origin URL from Request Node HTTP Server

I have a simple node http server set up currently, I'm trying to build the server so that it only accepts post requests from certain domains. I'm trying to get the domain of the server that made a post request to my node server but can't quite figure it out.

In my test environment, I am making the post request from localhost:3000 to my node server which is running on localhost:9220. I have been examining the req object but can't seem to find localhost:3000 mentioned anywhere in it.

http.createServer(function (req, res) {
    if(req.method == 'POST')
      {
         // Here is where I want to find the domain of the server 
         // making the request
      {
}).listen(9220);

It's probably simple but I am having trouble

thanks for the help!

#javascript #node-js

3 Likes1.55 GEEK