How do I get the domain originating the request in express.js?
- Node.js Version: v6.10.2
- OS: windows10
How do I get the domain originating the request in express.js? If I'm hitting from server2 to get server1 API data then I want to get details of server2 (i.e from which domain request is getting generated).
http://expressjs.com/en/4x/api.html is where express APIs are explained. Please see if req.ip helps you.
@gireeshpunathil has pointed you to the right place for current Express API docs, however, after a brief review of APIs there, you'll perhaps note the Express leverages the built-in 'http' module. As such, I think what you're asking regarding the server name is really a call to the underlying 'http' module APIs, unless you want to process the IP address as Gireesh directed? In that respect, perhaps what you want (servername) is found in the result of:
req.get('host')
ping @saurav2501
closing as answered, please re-open if it is still not working.
req.get('host') shows me backend instead of name of my virtual host.
use req.hostname for getting client side hostname if using express.js