StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

Broken Proxy* #41

Open joshuaaguilar20 opened 5 years ago

joshuaaguilar20 commented 5 years ago

HERE is the Latest Fix Thanks for a Great Class I would Love to Update some of this

https://github.com/facebook/create-react-app/issues/5103

//Just letting you know this proxy does not work anymore and I wondered if you had a fix? everytime I use it with current packages I get //this error "[1] When specified, "proxy" in package.json must be a string. //[1] Instead, the type of "proxy" was "object". //[1] Either remove "proxy" from package.json, or make it a string. //"

joshuaaguilar20 commented 5 years ago

I found the fix and could add it to the repo

First, install http-proxy-middleware using npm or Yarn:

$ npm install http-proxy-middleware --save $ # or $ yarn add http-proxy-middleware Next, create src/setupProxy.js and place the following contents in it:

const proxy = require('http-proxy-middleware')

module.exports = function(app) { // ... } Now, migrate each entry in your proxy object one by one, e.g.:

"proxy": { "/api": { "target": "http://localhost:5000/" }, "/*.svg": { "target": "http://localhost:5000/" } } Place entries into src/setupProxy.js like so:

const proxy = require('http-proxy-middleware')

module.exports = function(app) { app.use(proxy('/api', { target: 'http://localhost:5000/' })) app.use(proxy('/*.svg', { target: 'http://localhost:5000/' })) } You can also use completely custom logic there now! This wasn't possible before.

eponymz commented 5 years ago

Welp, i decided i should read up on that link.. oops. Deleting the whole package for is still not something that should be done.

joshuaaguilar20 commented 5 years ago

The problem is after learning this great course, I went to build real world projects that needed updates for security and what I learned on failed thats why IT MUST BE UPDATED or at least share the link for newbies. I think deleting the whole package JSON is not the answer that was a type error when I went to delete my comment. I would be happy to share the updates and the correct settings as it took me awhile to figure out why this one worked and mine did not. Thanks for reading, I was just hoping you could put out a notice and update readers. I know it makes selling the course easy, but somethings had NPM issues that forced me to update to comply with OWASP 2018. Thanks love all the work you guys have been putting out.