NestJS Dynamic template rendering in Fastify mode - res.render is not a function

1.7k Views Asked by At

I feel like Model-View-Controller @ docs.nestjs.com doesn't cover this use case - there is "Dynamic template rendering" section + Fastify but both combined together don't seem to work well.

I've tried the following snippet:

import { Get, Res } from '@nestjs/common'

@Get()
index(@Res() res) {
  if (isFoo()) {
    return res.render('template1.html', {var1: 'foo'})
  } else {
    return res.render('template2.html', {var2: 'bar'})
  }
}

and it fails with

TypeError: res.render is not a function

Is there any way to fix it?

Just to be clear, the reason I'm not using @Render is because I need conditional logic inside that action.

1

There are 1 best solutions below

2
On BEST ANSWER

res.render() is the express method. For Fastify, you need to install point-of-view and use res.view()