kaay
kaay

Reputation: 41

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

Upvotes: 0

Views: 1117

Answers (2)

Abdurrahim Ahmadov
Abdurrahim Ahmadov

Reputation: 561

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

Upvotes: 0

Kaleem Shoukat
Kaleem Shoukat

Reputation: 859

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;

Upvotes: 0

Related Questions