Using Nuxt routeRules as a reverse proxy

Created by Donald Ng, Modified on Wed, 21 Aug at 8:16 AM by Donald Ng

Nuxt 3 uses Nitro under the hood, which provides the routeRules config that can be used to proxy requests from one route to another.


To do this, add the following routeRules to your nuxt.config.ts file:

// nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/mida/**': { proxy: 'https://cdn.mida.so/**' },
},
});


Then configure the Mida.so client to send requests via your new proxy:

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


Replace 'XXXXXX' with your actual Mida.so key.


After making these changes, deploy your Nuxt 3 application. You can verify that Mida.so requests are being sent through your proxy by checking the network tab in your browser's developer tools. You should see requests going to https://your-host.com/mida instead of directly to cdn.mida.so.

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