Skip to content

Conversation

joshuaaguilar20
Copy link

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

facebook/create-react-app#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
Copy link
Author

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.

Copy link

@eponymz eponymz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That error you received actually suggests that one of your dependencies was incorrectly updated. I still have my proxies set up this way and it works fine. I would suggest that you try deleting your package-lock file and running npm install again. I experienced the same when i tried manually updating my lock file. Also I'd say you should add your lock file to your ignore. Your project won't depends on it since those are all dependencies of your specified dependencies. Deleting this file isn't a good idea since it is pretty much the bread and butter of a react project, similar to a manifest file.

@eponymz
Copy link

eponymz commented Nov 26, 2018

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
Copy link
Author

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.

@StephenGrider StephenGrider force-pushed the master branch 2 times, most recently from 5b859eb to c619692 Compare December 3, 2019 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants