Astro Info
Astro v6.1.3
Vite v7.3.1
Node v25.8.2
System macOS (x64)
Package Manager npm
Output static
Adapter @astrojs/cloudflare (v13.1.7)
Integrations none
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
server.allowedHosts (and vite.preview.allowedHosts) are ignored when using astro preview with the @astrojs/cloudflare adapter. Requests with non-localhost Host headers are blocked with a 403.
This was fixed for the static preview server in #16104, but the @astrojs/cloudflare adapter has its own preview entrypoint that is not covered by that fix.
Reproduce
npm install
npm run build
npm run preview
# In another terminal:
curl -H "Host: foo.example.com" http://localhost:4010/
Actual
< HTTP/1.1 403 Forbidden
Blocked request. This host ("foo.example.com") is not allowed.
To allow this host, add "foo.example.com" to `preview.allowedHosts` in vite.config.js.
What's the expected result?
200 response (.example.com is in server.allowedHosts).
Root cause
Two issues:
-
astro core does not pass server.allowedHosts to adapter preview entrypoints.
In packages/astro/src/core/preview/index.ts, the call to previewModule.default() includes host, port, headers, etc. but omits allowedHosts.
-
@astrojs/cloudflare preview entrypoint hardcodes allowedHosts: [].
In packages/cloudflare/src/entrypoints/preview.ts, the Vite preview config sets allowedHosts: [], ignoring any user configuration.
Workaround
Patch the adapter's preview entrypoint via a postinstall script in package.json:
"postinstall": "node -e \"let f=require('node:fs'),p='node_modules/@astrojs/cloudflare/dist/entrypoints/preview.js';f.existsSync(p)&&f.writeFileSync(p,f.readFileSync(p,'utf8').replace('allowedHosts: []','allowedHosts: true'))\""
Link to Minimal Reproducible Example
https://github.com/adamchal/astro-cloudflare-preview-allowedhosts
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
server.allowedHosts(andvite.preview.allowedHosts) are ignored when usingastro previewwith the@astrojs/cloudflareadapter. Requests with non-localhostHostheaders are blocked with a 403.This was fixed for the static preview server in #16104, but the
@astrojs/cloudflareadapter has its own preview entrypoint that is not covered by that fix.Reproduce
Actual
What's the expected result?
200 response (
.example.comis inserver.allowedHosts).Root cause
Two issues:
astrocore does not passserver.allowedHoststo adapter preview entrypoints.In
packages/astro/src/core/preview/index.ts, the call topreviewModule.default()includeshost,port,headers, etc. but omitsallowedHosts.@astrojs/cloudflarepreview entrypoint hardcodesallowedHosts: [].In
packages/cloudflare/src/entrypoints/preview.ts, the Vite preview config setsallowedHosts: [], ignoring any user configuration.Workaround
Patch the adapter's preview entrypoint via a postinstall script in
package.json:Link to Minimal Reproducible Example
https://github.com/adamchal/astro-cloudflare-preview-allowedhosts
Participation