0

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

kaay
  • 41
  • 5

2 Answers2

0

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;
Kaleem Shoukat
  • 811
  • 6
  • 14
0

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

  • Thank you. How can I add it into "server.register" ? – kaay May 11 '22 at 13:36
  • you can save it in the app.locals object, for example: `app.locals.url = req.hostname + req.originalUrl ` and you can use it everywhere. Once set, the value of app.locals properties persist throughout the life of the application. Let me know if this solves your problem – Abdurrahim Ahmadov May 11 '22 at 13:44
  • @kaay in the Hapi framework, you can use `server.app=request.info.hostname+request.path` – Abdurrahim Ahmadov May 11 '22 at 14:15
  • Hello again, I try to do it, but :), on ```server.ext('onPreResponse', function (request, reply) { console.log(request.info.hostname); // ==> I have the hostname ;) .... }) ... server.register({ register: require('./libs/hapi-passport-saml'), options: { callbackUrl: /* how can do it here */, issuer: ...., ... } } ... ``` – kaay May 12 '22 at 14:43
  • @kaay I mentioned above , assign it (`request.info.hostname+request.path`) to `server.app.url ` and use it ( `callbackUrl: server.app.url` ) everywhere you want – Abdurrahim Ahmadov May 12 '22 at 14:55
  • OK I do this : ` server.ext('onRequest', function (request, reply) { console.log("## server OnRequest : " + request.headers.host); /* => Get the URL : OK */ server.app.url = request.headers.host; ... }); server.ext('onPreResponse', function (request, reply) { console.log("## server OnRequest : " + request.headers.host); /* => Get the URL : OK */ server.app.url = request.headers.host; ... }); server.register({ register: require('./libs/hapi-passport-saml'), options: { callbackUrl: /* # 'server.app.url' => undefined # */, ... } }); ` – kaay May 16 '22 at 08:58