【问题标题】:NodeJS: How to redirect to an external URL?NodeJS:如何重定向到外部 URL?
【发布时间】:2020-12-17 14:58:34
【问题描述】:

我有一个 GET /auth 路由,它接受请求并需要重定向到外部资源(比如说 https://google.com),但不是将我重定向到 https://google.com,而是将我重定向到 http:localhost:3000/api/auth/https://google.com

是否可以以某种方式重定向到外部资源?因为现在它在我的路线中搜索路径https://google.com

这是我的路由器:

export const loginController = async (req: Request, res: Response, next: NextFunction) => {
  res.redirect('https://google.com');
};

router.get('/login', loginController);

【问题讨论】:

标签: javascript node.js express routes


【解决方案1】:

你需要像这样使用查询参数:

http:localhost:3000/api/auth?redirectUrl=https://google.com
export const loginController = async (req: Request, res: Response, next: NextFunction) => {
  const { redirectUrl } = req.query
  res.redirect(redirectUrl);
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 2017-12-11
    • 2012-01-10
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 2016-09-09
    相关资源
    最近更新 更多