Using Vercel rewrites as a reverse proxy

Created by Donald Ng, Modified on Mon, 2 Sep at 8:55 AM by Donald Ng

Vercel supports rewrites which we can use as a reverse proxy. Create a vercel.json file and add a rewrites object from the /mida route.

{
"rewrites": [
{
"source": "/mida/:path*",
"destination": "https://cdn.mida.so/:path*"
}
]
}


Some frameworks, like SvelteKit and Astro, require a hungrier regex pattern like:

{
"rewrites": [
{
"source": "/mida/:path(.*)",
"destination": "https://cdn.mida.so/:path*"
}
]
}


Note: Some frameworks, like T3 app, don't support Vercel rewrites well. If neither of these options work, we recommend trying another proxy method.


Once done, set the /mida route of your domain as the md_cdn in your Mida.so initialization like this:

<script>
window.md_cdn = 'https://www.your-domain.com'
</script>
<script src="https://www.your-domain.com/mida/js/optimize.js?key=XXXXXX" />


Once updated, deploy your changes on Vercel and check that Mida.so requests are going to https://www.your-domain.com/ by checking the network tab on your domain.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article