javascript - How do I get the domain originating the request in express.js? -
i'm using express.js , need know domain originating call. simple code
app.get( '/verify_license_key.json', function( req, res ) { // how domain req or res object? mean need know if api called somesite.com or someothersite.com. tried doing console.dir of both req , res got no idea there, read documentation gave me no help.
you have retrieve host header.
var host = req.get('host'); it optional http 1.0, required 1.1. and, app can impose requirement of own.
if supporting cross-origin requests, instead use origin header.
var origin = req.get('origin'); note cross-origin requests require validation through "preflight" request:
req.options('/route', function (req, res) { var origin = req.get('origin'); // ... }); if you're looking client's ip, can retrieve with:
var userip = req.socket.remoteaddress; note that, if server behind proxy, give proxy's ip. whether can user's ip depends on info proxy passes along. but, it'll typically in headers well.
Comments
Post a Comment