gpt4 book ai didi

node.js - 在 ExpressJS 中创建链接有什么简单的方法吗?

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:28 25 4
gpt4 key购买 nike

有时我需要在网站中创建绝对链接。

http://example.com/xxxx/xxxx?foo=bar而不是/xxxx/xxxx?foo=bar

这里有办法手动创建一个简单的快速助手吗?

就像:

app.locals.url = function ( pathTo, opts ) {
// Somethings here.
}

我认为他们可能需要 SSL 检查、主机和路由检查或其他东西。

最佳答案

您可以创建完整的 URL:

var URL = req.protocol + '://' + req.get('host') + req.originalUrl;

您可以重定向到此 URL

关于node.js - 在 ExpressJS 中创建链接有什么简单的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35059486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com