'Nodejs - Get client url (dns name) on server side
I want to get client url, on server side to continue (redirect) after authication process : Inside my script :
...
server.register({
register: require('./libs/hapi-passport-saml'),
options: {
callbackUrl: /* I want to put client url her */,
issuer: ....,
...
}
}
...
Thanks
Solution 1:[1]
You can do it like this: First require url package on top:
const url = require('url');
Then you can have client url in function:
const path = url.parse(req.url).path;
Solution 2:[2]
you can get full url using req.hostname and req.originalUrl properties.
app.get('/foo', (req,res)=>{
const clientUrl = req.hostname + req.originalUrl;
console.log(clientUrl);// yourdomainname.com/foo?s=4 full url string
})
in the Hapi framework, you can use server.app.url=request.info.hostname+request.path and now you are able to use server.app.url everywhere you want
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kaleem Shoukat |
| Solution 2 |
