vercel / vercel/vercel

Vercel's Rewrite function doesn't work in React

Open
#8,012 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
16.3k
Forks
3.8k
Avg merge
2m
Merged PRs (30d)
1

Description

Am building an app that requires me to use a proxy server to connect with my backend server which is working perfectly locally. But when I wanna deploy, I saw that I need to create a vercel.json file and inside it will be my rewrites functions.

{
  "rewrites": [
    {
      "source": "/api/:path*",
      "destination": "https://zeeh.herokuapp.com/:path*"
    }
  ]
}

I have written this code here expecting vercel to proxy into my destination server but instead, It didn't do anything but to the port of which the app was hosted on.....

https://zeeh.herokuapp.com/api/test => The resource that I wanna access


(async () => {
      try {
        const { data } = await axios.get('/api/test');
        console.log(data);
      } catch (error) {
        console.log(error);
      }
    })();

How it is being called

and I was expecting to see this called

https://zeeh.herokuapp.com/api/test

but this took over

https://el-menus.vercel.app/api/test

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the vercel.json rewrite configuration and the deployed axios request to /api/test. Reproduce the request against the deployed app, compare the observed /api/test behavior with the Heroku destination, and confirm that the rewrite forwards the request as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
react
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.