Created
January 1, 2020 05:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "scripts": { | |
| "client": "npm start --prefix ./client", | |
| "server": "nodemon server.js", | |
| "dev": "concurrently \"npm run server\" \"npm run client\"" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var port = 5000; | |
| var express = require('express'); | |
| var app = express(); | |
| app.listen(port, () => { | |
| console.log(`\n[Server Start] Port ${port} opened!`) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const proxy = require('http-proxy-middleware'); | |
| module.exports = function (app) { | |
| app.use(proxy('/', {target: 'http://localhost:5000/'})) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-middlewareReference
https://stackoverflow.com/a/52620241/9422917