0

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.

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91

1 Answers1

5

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

Jay McDoniel
  • 57,339
  • 7
  • 135
  • 147
  • Property 'view' does not exist on type 'FastifyReply.... can you help me config point-to-view for nestjs? – mangovn Dec 03 '21 at 19:00
  • [The types are there, and they're doing declaration merging correctly](https://github.com/fastify/point-of-view/blob/master/index.d.ts#L4). So long as `point-of-view` is imported somewhere this should be fine – Jay McDoniel Dec 03 '21 at 23:14