You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have proxy defined in package.json in our react application and We use proxy between front-end (webpack) and back-end (express) during development as described here. package.json:
So as you can see it's simple proxy as described in documentation.
On the backend side (port 3001) we call another APIs (another rest services).
I have noticed that proxy calls from webpack (create-react-app) to express (backed) during development are really slow. (we work on Windows OS)
GET http://localhost:3000/endpoint/ -> ~600ms - 900ms (webpack -> express -> 3rd party rest api)
GET http://localhost:3001/endpoint/ -> ~150ms - 250ms (express -> 3rd party rest api)
GET http://restAPI:XYZ/endpoint/ -> ~150ms - 250ms (3rd party rest api direct call)
As you can see the time differences between proxy calls (port 3000) and direct calls - port (3001) - are really huge. I expected delay but this looks weird.
Also sometimes large JSON response (~38KB) from proxy is broken (invalid - e.g missing some parts of a response or swapped characters). I have been struggling with the same issue on backend side and I think I have resolved it with proxy-agent where I set keep-alive connection.
Do you have any idea why or how to improve proxy time and behavior?
We are forced to use react-app-rewired for custom agent. It's sad that we were not able to set our custom agent for devServer proxy. At least we didn't find a way how to make this work.
// config-overrides.js
module.exports = {
devServer: function(configFunction) {
return function(proxy, allowedHost) {
const config = configFunction(proxy, allowedHost);doesnt work very well
config.proxy.forEach(p => {
p.agent = agent; // new http.Agent({ keepAlive: true });
});
return config;
};
}
}
I guess it's workaround and potentially not supported in the future releases of create-react-appbut response time is around 150ms - 230ms (AND! without invalid JSONs) and it's the thing that counts right now.
ENVIRONMENT:
Windows 10 Version 1703
npm --version 5.7.1
node --version v8.9.1
Reacted by Martin Brisiak, martinculen, TomasZigardi and VladoDemcak
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
Activity
VladoDemcak commentedon Mar 3, 2018
We are forced to use react-app-rewired for custom agent. It's sad that we were not able to set our custom agent for
devServerproxy. At least we didn't find a way how to make this work.I guess it's workaround and potentially not supported in the future releases of
create-react-appbut response time is around 150ms - 230ms (AND! without invalid JSONs) and it's the thing that counts right now.yyfearth commentedon Mar 11, 2018
I think the
proxy.jsmentioned in #3366 and #3845 will solve your problem.VladoDemcak commentedon Mar 12, 2018
Nice note @yyfearth !. Didn't know about
proxy.js. I checked it and I definitely agree with you.stale commentedon Dec 2, 2018
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
stale commentedon Dec 8, 2018
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.