nest.js @Post 设置响应的内容类型

Ki_*_*Ki_ 5 api post content-type typescript nestjs

我正在尝试为我的 API 实现一个 POST 端点,它在调用时返回一个 HTML 字符串。

我的代码目前看起来像这样:

import { Controller, Post } from '@nestjs/common';
@Controller()
export class MyController {
    @Post('/endpoint')
    public create(): string {
        return `
            <!DOCTYPE html>
            …
            </html>`;
    }
}
Run Code Online (Sandbox Code Playgroud)

如何告诉 POST 端点将正确的内容类型与其响应一起发送?我搜索了所有文档,但找不到任何对我有用的东西。

预先感谢您的帮助

Ki_*_*Ki_ 12

我自己找到了答案。我刚刚在@Header装饰器后面添加了装饰@Post器:

import { Header } from '@nestjs/common'

@Post('/endpoint')
@Header('content-type', 'text/html')
public create(): string {
  //
}
Run Code Online (Sandbox Code Playgroud)