Skip to content

Instantly share code, notes, and snippets.

@asamountain
Created January 1, 2020 05:19
Show Gist options
  • Select an option

  • Save asamountain/577d3f528d7fb149a8946516693dfb74 to your computer and use it in GitHub Desktop.

Select an option

Save asamountain/577d3f528d7fb149a8946516693dfb74 to your computer and use it in GitHub Desktop.
nodeJs(Express) server struggled to connect its proxy with view of ReactJs class. and this is the solution https://stackoverflow.com/a/52620241/9422917
"scripts": {
"client": "npm start --prefix ./client",
"server": "nodemon server.js",
"dev": "concurrently \"npm run server\" \"npm run client\""
}
var port = 5000;
var express = require('express');
var app = express();
app.listen(port, () => {
console.log(`\n[Server Start] Port ${port} opened!`)
})
const proxy = require('http-proxy-middleware');
module.exports = function (app) {
app.use(proxy('/', {target: 'http://localhost:5000/'}))
}
@asamountain
Copy link
Author

asamountain commented Jan 1, 2020

Tried to build a React-nodejs(express) app through this guide.
Other advice was not working for me. So some hours wasted.

you need to install 'http-proxy-middleware'

npm i --save http-proxy-middleware

Reference

https://stackoverflow.com/a/52620241/9422917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment