Astro hybrid output response headers #8739
-
Is it the expected behavior of Astro's hybrid output to ignore the headers set in the Suppose the following page exists: export const prerender = true
export async function GET(): Promise<Response> {
return new Response('Hello World!', {
status: 200,
headers: {
'content-type': 'text/plain; charset=utf-8'
}
})
} My assumption would be that Astro would create a file containing the actual response body In the generated output a file containing the "Hello World!" string exists in the client directory, Astro manifestThis is a simplified and stripped down example containing only the "prerender" route: {
"adapterName": "@astrojs/node",
"routes": [
{
"file": "prerender",
"links": [],
"scripts": [],
"styles": [],
"routeData": {
"route": "/prerender",
"isIndex": false,
"type": "endpoint",
"pattern": "^\\/prerender\\/?$",
"segments": [
[
{
"content": "prerender",
"dynamic": false,
"spread": false
}
]
],
"params": [],
"component": "src/pages/prerender.ts",
"pathname": "/prerender",
"prerender": true,
"fallbackRoutes": [],
"_meta": {
"trailingSlash": "ignore"
}
}
}
],
"base": "/",
"trailingSlash": "ignore",
"compressHTML": true,
"componentMetadata": [],
"renderers": [],
"clientDirectives": [],
"entryModules": {
"/src/pages/prerender.ts": "chunks/prerender_CxqmRQwW.mjs"
},
"inlinedScripts": [],
"assets": [
"/prerender"
],
"buildFormat": "directory",
"checkOrigin": false,
"rewritingEnabled": false,
"experimentalEnvGetSecretEnabled": false
} I have created a StackBlitz example that includes the relevant settings and files.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is expected for prerendered routes. For anything that is pre-rendered Astro behaves essentially as a static site generator: it creates static HTML, CSS, etc. Deciding on MIME type headers etc. should then be done by whatever server ends up serving these static files. Usually this is done using a file extension — for example if you rename your example file to |
Beta Was this translation helpful? Give feedback.
This is expected for prerendered routes. For anything that is pre-rendered Astro behaves essentially as a static site generator: it creates static HTML, CSS, etc. Deciding on MIME type headers etc. should then be done by whatever server ends up serving these static files. Usually this is done using a file extension — for example if you rename your example file to
src/pages/prerender.txt.ts
, it will generate aprerender.txt
file and runningnpm run preview
will show the correctContent-Type
header.