From 1f12632738a0107ece05c4fa05c05ccca1fba1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A0=20L=C3=AA?= Date: Thu, 23 May 2024 17:49:50 +0700 Subject: [PATCH] Update mvc.md Add alternative way to response view on fastify platform --- content/techniques/mvc.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/techniques/mvc.md b/content/techniques/mvc.md index 667fa344bb..100af770be 100644 --- a/content/techniques/mvc.md +++ b/content/techniques/mvc.md @@ -197,6 +197,17 @@ export class AppController { } } ``` +Alternatively, you can inject the `@Res()` decorator and response which view you want as follows: + +```typescript +import { Res } from '@nestjs/common'; +import { FastifyReply } from 'fastify'; + +@Get() +root(@Res() res: FastifyReply) { + return res.view('index.hbs', { title: 'Hello world!' }); +} +``` While the application is running, open your browser and navigate to `http://localhost:3000`. You should see the `Hello world!` message.