[英]How to redirect in nestjs Application other than res.redirect
I want to redirect to a website(in NestJs Application) but using the res() from express is not applicable for me我想重定向到一个网站(在 NestJs 应用程序中),但是使用 express 中的 res() 不适用于我
import { Response } from 'express';
@Get('qrmenu/business/:id')
public async ResponseToQRScan(@Param() params: IdValidator, @Res() res: Response,
@Query() qrQuery: QrScanQueryDto): Promise<any> {
console.log(qrQuery)
if (qrQuery.app !== true || !qrQuery.app) {
return res.redirect(`https://masovison.com/about/`)
}
let menu = await this.menuService.getMenuOfABusiness(params.id);
// console.log(menu)
res.send({ menu })
} }
PS: The Redirect is a conditional situation so controller should either redirect to a website or send the response as per condition. PS:重定向是有条件的情况,因此 controller 应该重定向到网站或根据条件发送响应。
is there any other way that I can redirect to a website in NestJS application?有没有其他方法可以重定向到 NestJS 应用程序中的网站?
You would either use the @Redirect()
decorator or call res.redirect()
directly as stated here .您可以使用
@Redirect()
装饰器或按此处所述直接调用res.redirect()
。 And also:并且:
Returned values will override any arguments passed to the
@Redirect()
decorator.返回值将覆盖传递给
@Redirect()
装饰器的任何 arguments。 For example:例如:
@Get('docs') @Redirect('https://docs.nestjs.com', 302) getDocs(@Query('version') version) { if (version && version === '5') { return { url: 'https://docs.nestjs.com/v5/' }; } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.