create-react-app proxy requests to php backend
It turns out that by starting my php backend with $ php -S localhost:8888 -t public
was causing the brunt of the problem. After digging through create-react-app issues I found that one user was having a similar issue with a php backend (https://github.com/facebookincubator/create-react-app/issues/800).
The solution is to start the server like so: $ php -S 0.0.0.0:8888 -t public
this will allow create-react-app to properly proxy requests to the php server. This also allowed me to curl localhost:8888
Additionally, I needed to uncomment always_populate_raw_post_data = -1
in my php.ini file per (Warning about `$HTTP_RAW_POST_DATA` being deprecated)
My setup as follows:
package.json
{ "name": "client", "version": "0.4.2", "private": true, "devDependencies": { "enzyme": "^2.6.0", "react-addons-test-utils": "^15.4.1", "react-scripts": "0.7.0" }, "dependencies": { "isomorphic-fetch": "^2.2.1", "react": "^15.4.1", "react-dom": "^15.4.1", "react-router-dom": "^4.2.2" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, "proxy": "http://localhost:8888/"}
fetch from client-side
function login(userData, onError, cb) { return fetch('/v1/auth/login', { // <-- this works correctly now method: 'post', body: JSON.stringify(userData), headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }).then(checkStatus) .then(parseJSON) .then(cb) .catch(onError);}
Hopefully this will help anyone else experiencing a similar issue.