-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Comments
Also, please provide a reproduction. Even if it doesn't work on Stackblitz, we can download it and run it ourselves |
Hello @andrewflbarnes. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Thanks for the response @ematipico
Should I rename this ticket to something like "incorrect astro preview errors and intellisense for vite preview" given the below?
What is the astro configuration which does this? I've had a look through the astro docs and done some googling but wasn't able to find any astro config which seemed to address this. Very possible I missed it since was searching for "allowedHosts" which may have been a red herring given the error message is wrong. |
Yeah, I suppose the bug is that we don't use any |
What about the other two issues? Namely
|
Not sure if this would be good enough. For example, part of my workflow when working on some changes, mostly CSS or a11y related, is to start a dev or prod server, make some changes, and then starting a tunnel, e.g. from cloudflare or ngrok, to share the preview with other devices so I can easily test the changes on a mobile, a Windows machine, etc. This workflow is no longer possible now since Vite 6.0.9 I guess and there is no way to configure anything like mentioned in the error message so that it can work as before if I'm not mistaken. |
Bjorn mentioned that the preview server uses Vite, but it's more an implementation detail than something that users can configure. What's your suggestion @HiDeoo? |
Definitely, and this is confirmed at the moment by the fact that the following configuration does nothing: vite: {
preview: {
port: 3000,
},
}, You have to use Considering that and the recent Vite Altho, even tho it's an implementation detail right now, I think it's now starting to leak into the user experience as what I consider a relatively common usage, is now showing a Vite error with guidance on how to fix it but following the guidance doesn't work. Not sure if this should be revisited or not as I may not have the full context. In the meantime, I found a workaround by using the __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=foo.example.com pnpm astro preview |
@HiDeoo thank you so much. I ran into this just a few minutes ago. |
Thank you @HiDeoo , I think your suggestion makes sense to me! I don't think we need a full fledged RFC for this, so if anyone wants to send PR, you're more than welcome to contribute. |
It doesn't work for bun. |
Same issue! But for some reason recently one of my projects failed and instead of my website I can see only message like topic starter:
With my domain, of cause. Workaround suggested by @HiDeoo helped, so thank you! But I thinks it's some kind of bug here |
I'm running on astro 5.3.0 and I no longer see this issue when adding these line in import { defineConfig } from "astro/config";
...
export default defineConfig({
...
vite: {
server: {
allowedHosts: ['<enter host name here>']
},
}
}) |
Thank you so much, it helped me, but I can't allow all hosts :( i don't know why :( |
Astro Info
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
Updating the corresponding part of
astro.config.mjs
(vite.preview.allowedHosts
) does not work, nor does setting it to true or adding avite.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:
package.json scripts
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 athttp://my-hostname
Link to Minimal Reproducible Example
https://github.com/andrewflbarnes/bug-astro-preview-allowedhosts
Participation
The text was updated successfully, but these errors were encountered: