withastro / astro

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

External redirects broken with Vercel adapter #11313

Open wotschofsky opened 6 days ago

wotschofsky commented 6 days ago

Astro Info

Astro                    v4.11.0
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/vercel/serverless
Integrations             none

(from CodeSandbox)

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

No response

Describe the Bug

Redirects defined in astro.config.mjs are improperly transformed by the Vercel adapter during build, making it impossible to redirect to an external URL.

Example: https://google.com -> /https:/google.com

The adapter always runs the redirect destination through Node's path.join while prepending the projects base path (usually /). Therefore external redirects are "destroyed" and converted into local redirects like shown above.

The final redirects for deployment are defined inside of .vercel/output/config.json

See https://vercel-redirect-repro.vercel.app for deployed example

What's the expected result?

Automatically detect external redirects, for example based on whether a protocol is defined, and skip any transformation logic to preserve the original redirect

Link to Minimal Reproducible Example

https://codesandbox.io/p/devbox/hopeful-scooby-cpzf5m

Participation

ematipico commented 4 days ago

I don't think this is a bug, our redirects, by design, aren't meant to handle external redirects:

https://github.com/withastro/roadmap/blob/main/proposals/0041-redirects.md#non-goals

This means that if you need to handle external redirects, you'll have to use - most probably - vercel.json

wotschofsky commented 4 days ago

I see, wasn't aware of this. Given that the Cloudflare adapter supports external redirects, I was assuming external redirects should be supported.

But if the platform supports external redirects, why not allow them to be configured adapter-agnosticly through the Astro config?

ematipico commented 4 days ago

Because Astro doesn't know which platform you will use, and that's where the adapter comes into play. We could consider e feature request for the Vercel adapter, it that's doable