Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aastro preview doesn't respect vite preview allowedHostnames in astro config #13060

Open
1 task
andrewflbarnes opened this issue Jan 24, 2025 · 2 comments
Open
1 task
Labels
needs repro Issue needs a reproduction

Comments

@andrewflbarnes
Copy link

andrewflbarnes commented Jan 24, 2025

Astro Info

Astro                    v5.1.9
Node                     v22.6.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/starlight

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When running astro preview and visiting the site from another device via the hostname I am met with the below message

Blocked request. This host ("my-hostname") is not allowed.
To allow this host, add "my-hostname" to `preview.allowedHosts` in vite.config.js.

Updating the corresponding part of astro.config.mjs (vite.preview.allowedHosts) does not work, nor does setting it to true or adding a vite.config.js file with this set.

The corresponding property for astro dev (vite.server.allowedHosts) does work.

Note: not reproducible on stackblitz (probably because it forwards direct to the IP).
Can be done with pnpm astro create on the starlight template (unable to check basic template at the moment but suspect it's an issue there too).

astro config:

 export default defineConfig({
   site: "http://my-hostname:54321",
   vite: {
     server: {
       allowedHosts: true,
     },
     preview: {
       allowedHosts: true,
     },
   },
...

package.json scripts

    "dev": "astro dev --port 54321 --host",
    "preview": "astro preview --port 54321 --host",

What's the expected result?

astro preview respects astro config vite.preview.allowedHosts - when I add "my-hostname"/true to this setting I am able to visit the site in a browser at http://my-hostname

Link to Minimal Reproducible Example

not reproducible on stackblitz - use astro create locally and add vite.preview.allowedHosts per description

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 24, 2025
@ematipico
Copy link
Member

ematipico commented Jan 24, 2025

astro preview doesn't use vite under the hoods, you would need to provide those hosts in a different way.

Also, please provide a reproduction. Even if it doesn't work on Stackblitz, we can download it and run it ourselves

@ematipico ematipico added the needs repro Issue needs a reproduction label Jan 24, 2025
Copy link
Contributor

Hello @andrewflbarnes. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue needs a reproduction
Projects
None yet
Development

No branches or pull requests

2 participants