withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.79k stars 2.48k forks source link

Hiding Astro behind a proxy with a base path in development #9989

Closed marcoacierno closed 6 months ago

marcoacierno commented 9 months ago

Astro Info

Astro                    v4.2.7
Node                     v18.17.1
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/tailwind

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 to localhost:8000/astro/schedule-builder.

The URL /astro/{path} forwards all the requests to the astro 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, inside vite, inside vite.server but all URLs that Astro creates in the page always point to the root.

E.g. a config I tried:

export default defineConfig({
  vite: {
    base: 'astro'
  },
  integrations: [react(), tailwind()],
  build: {
    format: "file",
    assetsPrefix: "//django-static/",
  },
});

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:

/@fs/home/projects/github-wrbpwn/node_modules/astro/dist/runtime/client/dev-toolbar/entrypoint.js?v=0a375a3a

Ideally this should be

/astro/@fs/home/projects/github-wrbpwn/node_modules/astro/dist/runtime/client/dev-toolbar/entrypoint.js?v=0a375a3a

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-wrbpwn?file=astro.config.mjs

Participation

lilnasy commented 9 months ago

I see you are using vite.base. Have you tried base?

https://docs.astro.build/en/reference/configuration-reference/#base

marcoacierno commented 9 months ago

I see you are using vite.base. Have you tried base?

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)

base / vite.base / vite.server.base they all do nothing to what Astro puts as paths in Githubissues.

  • Githubissues is a development platform for aggregating issues.