Hello,
I’m finding that the Content-Type
header I set in vercel.json
for my Serverless Function is not actually being set on my response. The other headers I define here are (Cache-Control,
Access-Control
), but for some reason Content-Type
is being ignored and the default text/plain;charset=UTF-8
is being applied.
Setting the Content-Type
header when returning a response from the function body works fine, but since all of my endpoints will return the same content type, I would rather configure this in vercel.json
.
Is this possible?
What doesnt work:
// api/helloWorld.ts
export function GET(request: Request) {
return new Response(JSON.stringify({hello: 'world'}));
}
// vercel.json
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"version": 2,
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "Content-Type", "value": "application/json" }, // ignored
{ "key": "Cache-Control", "value": "public, s-maxage=604800000" }, // applied
{ "key": "Access-Control-Allow-Credentials", "value": "true" } // applied
]
}
]
}
What does work:
// api/helloWorld.ts
export function GET(request: Request) {
return new Response(JSON.stringify({hello: 'world'}), {
headers:[
['Content-Type', 'application/json'] // applied
]
});
}
// vercel.json
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"version": 2,
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "Cache-Control", "value": "public, s-maxage=604800000" }, // applied
{ "key": "Access-Control-Allow-Credentials", "value": "true" } // applied
]
}
]
}