Replying to Avatar ると

Expressでcharset無しのContent-TypeでJSONを返すにはこうする必要があるって本当?

~~~

return res.status(200).setHeader('Content-Type', 'application/json').send(Buffer.from(JSON.stringify({ foo: "bar" }), 'utf-8'));

~~~

以下は全部だめ。

- `.json`でオブジェクトを渡す。

- `.send`でオブジェクトを渡す。

- `.send`で文字列を渡す。

- `.type`で`json`を指定する。

- `.type`で`application/json`を指定する。

- `.set`で`Content-Type`に`application/json`を指定する。

Avatar
ると 2y ago

KoaもFastifyもcharsetを付ける。Fastifyは明示的にヘッダをセットしてもダメっぽい。ううむ。

Reply to this note

Please Login to reply.

Discussion

No replies yet.