Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECONNRESET on proxy POST request #8653

Closed
kevinliyanto opened this issue Mar 15, 2020 · 3 comments
Closed

ECONNRESET on proxy POST request #8653

kevinliyanto opened this issue Mar 15, 2020 · 3 comments

Comments

@kevinliyanto
Copy link

kevinliyanto commented Mar 15, 2020

Hi there, I'm trying to set up a proxy between my TypeScript frontend using the "proxy" line on package.json:
"proxy": "http://localhost:5000"

I used WSL with this specific version: Linux DESKTOP 4.4.0-17763-Microsoft #864-Microsoft Thu Nov 07 15:22:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux. All development is done in the local machine and not intended for cloud purpose (for now).

Describe the bug

The backend system (Python, Flask-RestX with CORS and Flask-JWT-Extended) received the request properly and responded 200 (on the logs). However, I received this error when running yarn start:
Proxy error: Could not proxy request /auth/login from localhost:3000 to http://localhost:5000. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).

I managed to migrate all of my source code from TS/TSX into JS and JSX (because of this: #6794) but I still encountered the same problem. I tried using axios or fetch, and both gives the same result.

Did you try recovering your dependencies?

I checked that my Yarn version was not the most recent one (1.12.1). However, I still encountered the same problem once I updated it. I removed yarn.lock and node_modules to reinstall the new packages but it still doesn't work.

I decided to use npm (removed lock file and all modules, again), ran npm install and npm start. Still got the same problem.

The current yarn and npm version is:
yarn: 1.22.4 npm: 6.14.2

Which terms did you search for in User Guide?

Couldn't find this problem anywhere inside the docs. However, some people seemed to have encountered the same problem, and it was either webpack configuration:

or hpm:

I tried fixing the module manually by the suggestions provided above but it seems that they break my CRA. I'm not an expert on frontend framework issues, hence I might be wrong.

This issue was also created a year ago (#6329) without details

Environment

Environment Info:

  current version of create-react-app: 3.4.0
  running from /home/user/.npm/_npx/4763/lib/node_modules/create-react-app

  System:
    OS: Linux 4.4 Ubuntu 18.04.1 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.2 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    react: ^16.13.0 => 16.13.0
    react-dom: ^16.13.0 => 16.13.0
    react-scripts: 3.4.0 => 3.4.0
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. Create the app using create react app (TS/JS doesn't matter)
  2. Add a line that does POST request to proxy which routes to external API
  3. Run the dev server and do the request

Expected behavior

I expected the request to be forwarded (from the backend) by the proxy to the frontend.

Actual behavior

I encountered this problem with yarn start (as specified above):
image

The backend API server seems to work fine and didn't have any issue (no preflight request):
image

I tried fetching directly to the backend without proxy but it doesn't work (Flask responded with "OPTIONS" request), which was expected. I checked the OPTIONS request on the exact endpoint, and got this:
image

Reproducible demo

https://github.com/kevinliyanto/frontend_cors

Question

Is it possible for me to enable CORS on CRA by ejecting?

@kevinliyanto kevinliyanto changed the title ECONNRESET on ECONNRESET on proxy POST request Mar 15, 2020
@kevinliyanto
Copy link
Author

One interesting note: I had my python backend (port 5000) and CRA frontend (port 3000) running, and the proxy runs fine:
image

This thread chimurai/http-proxy-middleware#40 seems to have encountered the same problem as myself, and I'm not the only one who has spent 2 whole days trying to solve this.

Is it possible for CRA to implement (chimurai/http-proxy-middleware#40 (comment)), or is it something that webpack has to implement? Sorry that I don't really understand much on how to solve this issue.

@stale
Copy link

stale bot commented Apr 14, 2020

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 stale bot added the stale label Apr 14, 2020
@stale
Copy link

stale bot commented Apr 19, 2020

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.

@stale stale bot closed this as completed Apr 19, 2020
@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant