nodejs-在服务器端获取客户端URL(DNS名称)

发布于 2025-01-27 22:13:27 字数 370 浏览 4 评论 0原文

我想在服务器端 在验证过程后继续(重定向): 在我的脚本中:

    ...
    server.register({
        register: require('./libs/hapi-passport-saml'),
        options: {
            callbackUrl: /* I want to put client url her */, 
            issuer: ....,
            ...
        }
    }
    ...

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走野 2025-02-03 22:13:27

您可以这样做:
首先需要在最上方的URL包:

const url = require('url');

然后,您可以在函数中具有客户端URL:

const path = url.parse(req.url).path;

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;
幻梦 2025-02-03 22:13:27

您可以使用req.hostnamereq.originalurl属性获得完整的URL。

app.get('/foo', (req,res)=>{
   const clientUrl = req.hostname + req.originalUrl;
   console.log(clientUrl);// yourdomainname.com/foo?s=4  full url string
})

在HAPI框架中,您可以使用server.app.url = request.info.hostname+request.path,现在您可以使用server.app.url到处你想要

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文