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 1/2] 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. From 73cf9c7505afd2572f5ad9a9d2d4a2ebf05c45db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Thu, 17 Oct 2024 12:47:00 +0200 Subject: [PATCH 2/2] chore: improve wording --- content/techniques/mvc.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/content/techniques/mvc.md b/content/techniques/mvc.md index 8d6af03981..e2d88e717d 100644 --- a/content/techniques/mvc.md +++ b/content/techniques/mvc.md @@ -182,7 +182,9 @@ async function bootstrap() { bootstrap(); ``` -The Fastify API is slightly different but the end result of those methods calls remains the same. One difference to notice with Fastify is that the template name passed into the `@Render()` decorator must include a file extension. +The Fastify API has a few differences, but the end result of these method calls is the same. One notable difference is that when using Fastify, the template name you pass into the `@Render()` decorator must include the file extension. + +Here’s how you can set it up: ```typescript @@filename(app.controller) @@ -197,7 +199,8 @@ export class AppController { } } ``` -Alternatively, you can inject the `@Res()` decorator and response which view you want as follows: + +Alternatively, you can use the `@Res()` decorator to directly inject the response and specify the view you want to render, as shown below: ```typescript import { Res } from '@nestjs/common';