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

Vercel rewrites not working #6446

Closed
1 task
Ehesp opened this issue Mar 7, 2023 · 9 comments
Closed
1 task

Vercel rewrites not working #6446

Ehesp opened this issue Mar 7, 2023 · 9 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority) needs response Issue needs response from OP pkg: vercel Related to Vercel adapter (scope)

Comments

@Ehesp
Copy link

Ehesp commented Mar 7, 2023

What version of astro are you using?

2.0.18

Are you using an SSR adapter? If so, which one?

Vercel

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

Rewrites inside of a vercel.json file are not applied (note, redirects do seem to work).

Also see https://discord.com/channels/830184174198718474/1077242845406167112/1077242845406167112

To reproduce, add this to your vercel.json and deploy:

{
  "rewrites": [
    {
      "source": "/",
      "destination": "/page2"
    }
  ]
}

See repro link below. The index page should rewrite to page2:

https://astro-vercel-rewrites.vercel.app/

Link to Minimal Reproducible Example

https://github.com/Ehesp/astro-vercel-rewrites

Participation

  • I am willing to submit a pull request for this issue.
@ematipico ematipico added pkg: vercel Related to Vercel adapter (scope) - P4: important Violate documented behavior or significantly impacts performance (priority) labels Mar 9, 2023
@ivoilic
Copy link
Contributor

ivoilic commented Mar 11, 2023

This is also true for rewrites in Vercel middleware.
Related discussion: withastro/roadmap#261

ivoilic added a commit to ivoilic/astro that referenced this issue Mar 11, 2023
Currently using rewrite with static files works but server rendered files with either edge or serverless function don't get rewritten.
See: withastro#6446
@natemoo-re natemoo-re self-assigned this Mar 13, 2023
@cruzlutor
Copy link

Same issue here, but in my case, it fails only with the root. For sub-directories it works well

@ivoilic
Copy link
Contributor

ivoilic commented Mar 14, 2023

@cruzlutor are those sub directories static? Vercel itself handles rewrites for static content. It’s SSR content where Astro needs to handle the rewrite headers.

matthewp pushed a commit that referenced this issue Apr 12, 2023
Currently using rewrite with static files works but server rendered files with either edge or serverless function don't get rewritten.
See: #6446
@natemoo-re
Copy link
Member

Hey y'all, circling back to this! We've landed middleware support in Astro and edge middleware support for our Vercel adapter, so I'd recommend leaning on those features to accomplish this for now.

After discussing this with the team, we agree that respecting vercel.json would be a nice enhancement, but since don't have a rewrite primitive like Next.js does, it would be quite a bit of work to add. Definitely a future enhancement we're considering! But hopefully middleware solves your need for now.

@natemoo-re natemoo-re added - P2: nice to have Not breaking anything but nice to have (priority) and removed - P4: important Violate documented behavior or significantly impacts performance (priority) labels Jun 29, 2023
@kidonng
Copy link
Contributor

kidonng commented Jul 2, 2023

From what I can observe, rewrites for non-existent pages do work, i.e. existing Astro pages takes precedence when they conflict with Vercel config.

@firxworx
Copy link

firxworx commented Aug 3, 2023

I was reporting a different issue and saw just how many open issues relate to Vercel and figured I'd share the only way I figured out to ship a recent (April/May) Astro project for my client was to ditch Vercel.

I had so many issues with Vercel, middleware, etc -- Really any nontrivial Vercel feature with an Astro deployment. I had an i18n scenario with translated URL's + RTL where the whole nine yards of rewrites, edge functions, etc played a role.

I found myself in the same boat as y'all experimenting with different things, trying to understand what was working and what wasn't... nothing substantial is configurable and the "under the hood" of Vercel is not well documented... nor apparently well-understood by their support team either...

What worked?

I switched to S3 + CloudFront deployment (with Edge Lambda for any rewrites etc) and used GitHub Actions to implement the preview deployments and haven't looked back.

You can even do it in about as much time as it will take their support to turnaround ;)

AWS docs are often meh but in this case they provide extensive use-case based examples for both Edge Lambdas and Cloud Functions (take note of the difference for your use-case!) for CloudFront. GitHub is full of in-production examples as well.

Really I think Vercel knows their own dogfood well (NextJS) and after that good luck. I would still recommend Vercel for certain teams and use-cases however not for anything that's not NextJS.

At the time (and maybe even still) it felt like they hadn't even thought of the possibility that someone might have a monorepo aka a project where paths don't line up exactly to their presumably hardcoded scenarios for file paths to middleware and the like for any project that isn't NextJS. By making Vercel so "easy" and stripping all possibility of configuration I found it was impossible to get it to align with Astro in a completely typical Nx monorepo structure.

@natemoo-re natemoo-re removed their assignment Aug 8, 2023
@matthewp
Copy link
Contributor

Is this because we generate our own vercel.json and don't merge it with yours?

@matthewp matthewp added the needs response Issue needs response from OP label Aug 10, 2023
@ematipico
Copy link
Member

@Ehesp any updates? Could you please follow up?

@matthewp
Copy link
Contributor

Going to go ahead and close since there hasn't been any follow-up here. Please create a new issue if you are able to still reproduce this, thank you.

alexanderniebuhr pushed a commit to withastro/adapters that referenced this issue Aug 29, 2024
Currently using rewrite with static files works but server rendered files with either edge or serverless function don't get rewritten.
See: withastro/astro#6446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) needs response Issue needs response from OP pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants