Skip to content

Instantly share code, notes, and snippets.

@AnatoliyLitinskiy
Created September 25, 2018 15:02
Show Gist options
  • Save AnatoliyLitinskiy/9edbec3f82383ee40efdf977e5820506 to your computer and use it in GitHub Desktop.
Save AnatoliyLitinskiy/9edbec3f82383ee40efdf977e5820506 to your computer and use it in GitHub Desktop.
javascript proxy server

Here is a quick and dirty workaround if you need to run your dev app on domains other than localhost :

  1. Install concurrently and http-proxy
yarn add concurrently http-proxy || npm install --save-dev concurrently http-proxy
  1. 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);
  1. Replace the start script in your package.json by this
{
  // ...
  "scripts": {
    "start": "concurrently \"node proxy-server.js\" \"PORT=3000 react-scripts start\"",
    // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment