Application Proxies


Wed, 12 Mar 2025 00:00:00 GMT

Have you heard of application proxies? Apparently, if you set up an application proxy between your frontend and backend app, then CORS is no longer an issue. How amazing is that?

// webpack.config.js
module.exports = {
  //...
  devServer: {
    proxy: [
      {
        context: ['/api'],
        target: 'http://localhost:3000',
      },
    ],
  },
};

And I'm not talking about an Nginx proxy or an API gateway. I'm talking about something that is as simple as 3 lines of configurations inside your Vite/Webpack Dev-server setups.

You may wonder "Oh but how does that work? Once the website is live in production, who's responsible for maintaining the proxy?" Well, the answer is simple. You are!

So, here's the catch: application proxy only works for local development. Once you deploy your app, you need to set up the CORS headers on your server. But hey, at least you don't have to worry about CORS while developing your app.