[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Discussions](/c/community/4)

# Configurable rewrites

187 views · 4 likes · 6 posts


hpx7 (@hpx7) · 2025-02-03 · ♥ 2

I'm deploying a Vite SPA to Vercel, and my backend is deployed elsewhere. Vercel's rewrites feature is handy to allow proxying `/api/*` to my backend api url, but I don't want to commit my backend address to source control.

I'm working around this issue by writing the `vercel.json` as part of my Github Action:
```
      - name: Write vercel.json
        run: |
          cat <<EOF > vercel.json
          {
            "rewrites": [
              {
                "source": "/api/:path*",
                "destination": "${{ secrets.BACKEND_API }}/:path*"
              },
              {
                "source": "/(.*)",
                "destination": "/index.html"
              }
            ]
          }
          EOF
```

It would be good if this was more natively supported by Vercel


Anshuman Bhardwaj (@anshumanb) · 2025-02-03 · ♥ 1

Hi @hpx7, welcome to the Vercel Community!

I see what you mean. But, there is no other way to dynamically generate a `vercel.json`.

I'm curious to know why you want to keep your backend API as a secret because the frontend users will always know what the backend API url is. So, the URL itself is a public information anyways.

Please let me know if I misunderstood.


hpx7 (@hpx7) · 2025-02-03 · ♥ 1

@anshumanb the rewrites feature allows me to hide the backend API url from frontend users.

Lets say my backend API was `https://example.com`. With rewrites, the frontend users will see a call to `/api/foo`, which will be proxied to `https://example.com/foo` via Vercel rewrites. Does that make sense?


Anshuman Bhardwaj (@anshumanb) · 2025-02-04

Hi @hpx7, thanks for explaining your use case. But as of today, we don't have other way to support dynamic values in the `vercel.json` file. So, the solution you are using is the ideal one.


Masha Maltseva (@masha-maltseva) · 2025-07-29

Are there any plans to implement the solution for this?


Anshuman Bhardwaj (@anshumanb) · 2025-07-30

Hi @masha-maltseva, you can use the [has or missing object definition](https://vercel.com/docs/project-configuration#rewrite-has-or-missing-object-definition) to dynamically apply the rewrites or redirects. For example,

```json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "rewrites": [
    {
      "source": "/dashboard",
      "missing": [
        {
          "type": "cookie",
          "key": "auth_token"
        }
      ],
      "destination": "/login"
    }
  ]
}
```