Trying to create server side API for the client application. The client is written completely on react. In development is served with webdevserver on port 3000. The server is listening on port 3001.
I've added proxy to the package.json
file of the client app as following:
{
"name": "client",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.8.5"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-router": "^3.0.2",
"superagent": "^3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3001/"
}
but once I am requesting the server API it fails:
import Request from 'superagent';
export function searchTasks(text, callback) {
Request.get('http://localhost:3000/api/v1/tasks', response => {
callback(response.body.Search);
})
}
Response object is null. If I try to request API with 3001 port - everything works fine. It seems web-dev-server is not proxying the requests or, maybe, I missed some additional configuration options?