Skip to content

Question: Different results when using multiple proxies with react router. #2743

Closed
@HappyZombies

Description

@HappyZombies

So I created my react app and added react router, I have the proxy property in my package.json as so

"proxy": "http://myurl:1000"

http://myurl:1000 has an endpoint /users (so http://myurl:1000/users) that returns json data. With react router, I can create my own endpoint of the same name (http://localhost:3000/users) and I will get my component/page of users, not the JSON data.

And if I use fetch, axios, ajax etc to the endpoint of http://localhost:3000/users, I will get the json data. This all makes sense as you state in the WebpackDevServerUtils.js. However, how should I go about this for multiple proxies ?

On that same file of WebpackDevServerUtils.js and the same line, the context method is different when I specify a string (a single proxy), and the method you give for context is different when I specify an object (multiple proxies). See the code.

So I created this...

"proxy": {
    "/apiv2": {target: "http://differenturl:1001"},
    "/": {target: "http://myurl:1000"}
 }

With this, if I try to go to http://localhost:3000/users, in fact, any endpoint, it will go to the http://myurl:1000 endpoint and return me either the json data or a 404 page from the myurl:1000, not the react router page/component I have setup.

Keep in mind that http://myurl:1000 has, let's say, 20 end points. Will I have to specify each and every single one ? Or is there something I am missing/need to specify in the proxy object ? Any help with this would be appreciated, thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions