相当于NodeJS中的window.location和window.pathname

Equivalent of window.location and window.pathname in NodeJS

本文关键字:window pathname location 相当于 中的 NodeJS      更新时间:2023-09-26

NodeJS/ExpressJS中window.location.protocolwindow.location.host的等价物是什么?

我正在尝试使用第三方API将url重定向回我的网站。

NodeJS API url.format(urlObject)方法返回从urlObject派生的格式化url字符串。

var url = require('url');
function getFormattedUrl(req) {
    return url.format({
        protocol: req.protocol,
        host: req.get('host')
    });
}
res.redirect(getFormattedUrl(req));