【问题标题】:NestJS Dynamic template rendering in Fastify mode - res.render is not a functionFastify 模式下 NestJS 动态模板渲染 - res.render 不是函数
【发布时间】:2021-03-11 00:28:05
【问题描述】:

我觉得Model-View-Controller @ docs.nestjs.com 没有涵盖这个用例 - 有“动态模板渲染”部分 + Fastify 但两者结合在一起似乎效果不佳。

我已经尝试了以下 sn-p:

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'})
  }
}

它失败了

TypeError: res.render 不是函数

有什么办法可以解决吗?

为了清楚起见,我不使用 @Render 的原因是因为我需要该操作中的条件逻辑。

【问题讨论】:

    标签: nestjs fastify nestjs-fastify


    【解决方案1】:

    res.render() 是 express 方法。对于 Fastify,你需要安装 point-of-view 并使用 res.view()

    【讨论】:

    猜你喜欢
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 2015-04-11
    • 2020-03-11
    • 1970-01-01
    • 2014-12-08
    相关资源
    最近更新 更多