提问者:小点点

NodeJS:如何重定向到外部URL?


我有一个接受请求的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);

共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);
};