Here is a quick and dirty workaround if you need to run your dev app on domains other than localhost :
- Install concurrently and http-proxy
yarn add concurrently http-proxy || npm install --save-dev concurrently http-proxy
- Add proxy-server.js
var http = require('http');
var httpProxy = require('http-proxy');
httpProxy.createServer({
changeOrigin: true,
hostRewrite: true,
autoRewrite: true,
ws: true,
target: 'http://localhost:3000'
}).listen(process.env.PORT || 8080);
- Replace the start script in your package.json by this
{
// ...
"scripts": {
"start": "concurrently \"node proxy-server.js\" \"PORT=3000 react-scripts start\"",
// ...