I'm trying to make my application return "application/json" as the content type whenever the response is a json of course.
I have tried:
res.json(jsonContent);
response header has "Content-Type → text/plain; charset=utf-8"
and
res.setHeader('content-type', 'text/json');
res.send(jsonContent);
response header has "Content-Type → text/plain; charset=utf-8"
and
res.set('content-type', 'text/json');
res.send(jsonContent);
response header has "Content-Type → text/plain; charset=utf-8"
and all of the above at the same time. But my app always server responses as text/plain and never application/json. What might I be doing wrong?
As the documentation explains:
res.type('json'); // => 'application/json'
res.type('application/json'); // => 'application/json'
Sets the Content-Type HTTP header to the specified type.
Depending on your setup (and applied middleware), if the client's request was not made with Accept: application/json, then the response's content type might be getting set to just text/plain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With