Complete the code to send a redirect response to '/home' using NestJS.
return response.[1]('/home');
In NestJS, the redirect method on the response object sends a redirect response to the client.
Complete the code to inject the response object in a NestJS controller method.
import { Response } from 'express'; @Get() handleRequest(@[1]() response: Response) { return response.redirect('/dashboard'); }
The @Res() decorator injects the response object in NestJS controller methods.
Fix the error in the code to properly redirect with status 301 in NestJS.
return response.status([1]).redirect('/new-url');
Status code 301 means a permanent redirect. Using status(301) before redirect() sets this correctly.
Fill both blanks to create a redirect response with status 302 and URL '/login'.
return response.status([1]).[2]('/login');
Status 302 means temporary redirect. Use status(302) and then redirect() to send the redirect.
Fill all three blanks to create a NestJS controller method that redirects to '/profile' with status 307.
import { Controller, Get, Res } from '@nestjs/common'; import { Response } from 'express'; @Controller('user') export class UserController { @Get('redirect') redirectToProfile(@[1]() response: Response) { return response.status([2]).[3]('/profile'); } }
Use @Res() to inject response, status code 307 for temporary redirect, and redirect() method to send the redirect.