Home > Software engineering >  Nodejs - Get client url (dns name) on server side
Nodejs - Get client url (dns name) on server side

Time:05-11

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

CodePudding user response:

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;

CodePudding user response:

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

  • Related