Issue
I use fetch('htp://list-of-servers') that returns a list of urls
- test1.example.com
- test3.example.com
- test5.example.com
Then I need to perform a fetch() on each one of these urls: fetch('test1.example.com').then(...)
urls.map(url => fetch(url))
but
- a) url is not cors enabled (so I tried adding them in setupProxy)
- b) I don't know these urls in advance (since they're result of an earlier fetch, so I'm not sure how they can be added to setupProxy.js. I basically need some kind of equivalent to curl, that can request any non-cors remote url, but in js/react/node.
Suggestions?
Solution
Found a solution online. I have to run an express server/node app at the same time as the react client (different port), so client requests to url=test1.example.com
, would be written as fetch(`/api/${url}`)
then that would hit the express server localhost for proxying, where it would do a non-browser server-side request fetch(`http://${url}`)
where cors problems wouldn't be an issue. I needed an ELI5.
Answered By - Noon Time Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.