CORS issues when developing locally against a separate API server

Thanks for posting this here @tessier0ashpool. We actually solved on discord, but posting here to help others looking for a solution.

Solution currently is to tweak the webpack dev server config.

Step 1: Create webpack config

This should be placed in web/config/webpack.config.js

Step 2: Let’s add our proxy changes

We’re going to add /other-api to proxy to localhost:5000/other-api inour dev server config

module.exports = (config) => {
  config.devServer = {
    ...config.devServer,
    proxy: {
      ...config.devServer.proxy,
      '/other-api': 'http://localhost:5000',
    },
  }

  return config
}

All this is doing is preserving all of the dev server config, but also adding a new proxy path

Step 3: Restart dev server

Stop your RW dev server and run it again yarn rw dev


On a separate note, if you want to proxy in netlify, this is what you use https://docs.netlify.com/configure-builds/file-based-configuration/#redirects

1 Like