-
-
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
Hiding Astro behind a proxy with a base path in development #9989
Comments
I see you are using https://docs.astro.build/en/reference/configuration-reference/#base |
Yes, I tried it as well; the only thing it does is it force you to go to (in my example) /base-you-set/your-actual-path. I imagine to simulate how the address would be in production. (I updated the repro link https://stackblitz.com/edit/github-wrbpwn?file=astro.config.mjs to show if you open the inspector it always points to root)
|
Thanks for clarifying! This is not a use-case we had considered. We don't support it currently. You mention you are putting the dev server behind a proxy, as opposed to a production server. That is a very specific use-case. Is there something preventing development locally on your own machine? |
Thanks for checking it! I suspected it wasn't supported but didn't want to give up easily. I will close the issue as I suspect it is not really a use case worth spending much time on. About my use case: I described my setup quite badly, this is all for local development, and the production setup would just use the HTML files served directly by Django. While working on my project, I want everything to go through a Django server (running on my machine) because:
The problems I flagged here for my use case (especially authentication and iframes) would probably be solved quite easily with a good CORS setup and just letting Django know to allow localhost:3002 iframes when in local development but I naively assumed it was just a matter of setting a base path and it would be done and be on the same origin 😂 If anyone (for some reason?) wants to do something similar, this is what I did in my case:
At this point, I am not even sure I will keep this workaround as it might break easily with future Astro versions too! :) |
Thanks for providing context and resources for others. Good luck! |
I don't think this is an extreme use case. In such use cases there are clashes. I've had this problem in multiple occasions in two different jobs (with nuxt and astro specifically, due to @Vite stuff.) and I know others who had the same problem. I was expecting the below requests were like ".../astro/@Vite...", ".../astro/@fs..." having "/astro" base path prefixed before the request path. |
Need this. During the development phase, we have multiple ports split into different applications. After build release, it is one application, and pages with different prefixes come from different projects. I need to get through the session information of multiple applications on different ports, such as cookies or tokens. |
Can it be reopened? |
Happy to reopen as it seems multiple people actually have the same need :) I will leave it to the Astro team to decide if they want to fix it or not. |
So, there are two ways to go on about this, and that would depend on how much you can configure on the proxy you are adding in front of Astro. Suppose you send a request to
Whether the proxy in front is doing a rewrite changes things significantly because, in that case, the tree that is generated by Astro is not the tree that everything that gets generated refers to. This makes things much trickier on Astro's side. The first case seems reasonably straightforward to implement (not small tho), and I would be happy to guide someone to do that. The second case... I'd really prefer to just figure out how to not do a rewrite on whichever proxy is in front of Astro |
@Fryuni is this an Astro bug at all? I'm having trouble seeing one. |
I wouldn't say it is a bug because I don't think Astro has ever worked in that scenario. |
Hi team. it's really a feature request. |
Ah yes, this is not really possible with Astro dev server as it's not able to add prefixes for things like file URLs or This seems very easy to configure on your proxy server. Just make it remove the |
I know that this can be easily done under nginx. We are actually doing this now in a production. The situation is like this:
|
Please re-open this. We have 3 applications (from which 2 are astro projects) that we run under the same proxy. The production setup is ok, but the development environment is a nightmare to manage for the moment. |
This issue has been closed a while ago and this is not considered a bug AFAIK so any request made here will unfortunately go unnoticed. Please check if there's already a proposal for it at https://github.com/withastro/roadmap/discussions, and create one if not (feel free to share the link here)! |
I sort of need this. My reverse proxy routes all requests that are localhost:7080/astro/ to localhost:4321/astro The index page loads, but all the node modules are being requested as localhost:7080/node_modules, etc. hence, the page does not load properly. This is not a problem at all with angular by the way. My astro app already has the base: astro applied in the astroconfig file. Could I request the Astro team re-consider this feature? |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Hello!
I have a setup where I need to run Astro behind a "proxy" server in local development. Developers go to a Django server and navigate to (for example)
localhost:8000/admin/schedule-builder/
. This URL will render an iframe pointing tolocalhost:8000/astro/schedule-builder
.The URL
/astro/{path}
forwards all the requests to theastro dev
local server.To make this flow work, I need all URLs that Astro generates to be prefixed with the base /astro. I tried setting the
base
param in all places: at the root of the config, insidevite
, insidevite.server
but all URLs that Astro creates in the page always point to the root.E.g. a config I tried:
What's the expected result?
Astro should prefix all the URLs with the base when specified in the config
As an example, if you go to the repro link, you can see that the
<script>
tag src is:Ideally this should be
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-wrbpwn?file=astro.config.mjs
Participation
The text was updated successfully, but these errors were encountered: