Proxy setting not being applied to api calls
See original GitHub issueDescription
Adding "proxy": "url:port"
to my package.json
does not alter the port used in fetch requests.
Expected behavior
I have added "proxy": "http://localhost:8080"
to my package.json
within my root folder and so would expect that my fetch requests will be directed to this port.
Actual behavior
The requests are still going through to the port on which the create-react-app server is running, 3000 in this case. This has been observed using chrome network tools as well as using postman.
Environment
Run these commands in the project folder and fill in their results:
react-scripts@0.8.3
node: 7.2.0
npm: 4.0.5
yarn: 0.19.0-20161207.1240
Then, specify:
- Windows 10
- Chrome 55
Reproducible Demo
I’m not 100% sure on how to get a demo up and running, but here is the code that I am making my api call with and my package.json file for reference.
export function fetchEvents() {
return dispatch => {
fetch('/api/events')
.then(res => res.json())
.then(data => dispatch(setEvents(data.events)));
}
}
package.json
{
"name": "cra",
"version": "0.1.0",
"private": true,
"devDependencies": {
"flow-bin": "^0.36.0",
"react-scripts": "0.8.3"
},
"dependencies": {
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-redux": "^4.4.6",
"react-router": "4.0.0-alpha.6",
"redux": "^3.6.0",
"redux-devtools-extension": "^1.0.0",
"redux-thunk": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:8080"
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:21 (4 by maintainers)
Top Results From Across the Web
React proxy not conecting to api url - Stack Overflow
try setting "proxy": "127.0.0.1:6000" in your package.json file for your client.
Read more >Proxying API Requests in Development - Create React App
The development server will only attempt to send requests without text/html in its Accept header to the proxy.
Read more >Proxy Settings in the API Definition - Tyk.io
Any requests coming into the host, on the port that Tyk is configured to run on, that go to this path will have...
Read more >Set up a proxy integration with a proxy resource - Amazon API ...
The Lambda proxy integration, designated by AWS_PROXY in the API Gateway REST API, is for integrating a method request with a Lambda function...
Read more >404 Unable to identify proxy for host: <virtual host name> and url
If the API proxy is not configured to accept the requests for the specific path used in the API Request URL, then we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just ended up moving all my API endpoints to
/api
(and my static assets to/assets
)Now my server only cares about the
/api
stuff and serving static files and react handles everything else.I’m having the same problem, but no matter what port I change it to, React still points api calls to http://localhost:3000/ instead of the proxy I provide.
package.json:
My Response:
My server is definitely running on localhost:8080, I can send requests to it. I think React is just ignoring my proxy? I’ve restarted both the server and React multiple times, changing ports multiple times as well. @gaearon