Reputation: 63
I want to redirect to a website(in NestJs Application) but using the res() from express is not applicable for me
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.
is there any other way that I can redirect to a website in NestJS application ?
Upvotes: 1
Views: 1311
Reputation: 11994
You would either use the @Redirect()
decorator or call res.redirect()
directly as stated here. And also:
Returned values will override any arguments passed to the
@Redirect()
decorator. 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/' }; } }
Upvotes: 1