question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxy POST issue with react-scripts 1.0.x and standard HTML (login) form

See original GitHub issue

My app proxies all unknown requests to an external server (java).

Since version 1.0.0 (and up to latest 1.0.11) I cannot login any more. The login POST request is rejected with status 404 (the browser shows “Cannot POST /api/login”).

If I roll back to 0.9.x I can login again.

If already logged in, all other POST requests seem to be accepted.

Here is the network capture of the request:

POST /api/login HTTP/1.1
Host: 0.0.0.0:3000
Connection: keep-alive
Content-Length: 26
Cache-Control: max-age=0
Origin: http://0.0.0.0:3000
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.100 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
DNT: 1
Referer: http://0.0.0.0:3000/logout
Accept-Encoding: gzip, deflate
Accept-Language: fr,en-US;q=0.8,en;q=0.6
Cookie: sessionToken=339102761274932417

login=admin&password=admin
HTTP/1.1 404 Not Found
X-Powered-By: Express
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 23
Vary: Accept-Encoding
Date: Thu, 24 Aug 2017 14:37:43 GMT
Connection: keep-alive

Cannot POST /api/login

Is this a bug report?

EDIT: I guess not since I found the explanation in the user guide.

Maybe the doc on proxying could say that login forms implemented in pure HTML will not work since it generates an Accept:text/html header.

Can you also reproduce the problem with npm 4.x?

4.x not tried. I’m using 6.11.2

Which terms did you search for in User Guide?

“proxy”

I found the following information:

The development server will only attempt to send requests without a text/html accept header to the proxy.

This seems to explain my problem since my login form is a standard HTML form. I’m not sure I can prevent the browser to send text/html in its accept header.

Does it mean I have to tweak my login component to perform some ajax call instead of relying on standard HTML?

Environment

  1. node -v: v6.11.2
  2. npm -v: 3.10.10
  3. yarn --version: 0.27.5
  4. npm ls react-scripts: 1.0.11

Then, specify:

  1. Operating system: linux
  2. Browser and version: not relevant

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Johnny00520commented, Jul 26, 2018

Can I reopen this issue? I have the similar issue

0reactions
bugzpoddercommented, Jul 26, 2018

@Johnny00520 file new issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

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. Conveniently, this avoids CORS ...
Read more >
Could not resolve dependency error peer react@"^16.8.0
Try this npm config set legacy-peer-deps true npm i.
Read more >
Why you should use a proxy server with Create React App
In this article, we will discuss what a proxy server is, why you should use a proxy server in development, and uses cases...
Read more >
http-proxy-middleware - npm
The one-liner node.js proxy middleware for connect, express and browser-sync. Latest version: 2.0.6, last published: 8 months ago.
Read more >
504 Gateway Timeout - HTTP - MDN Web Docs
... Transfer Protocol (HTTP) 504 Gateway Timeout server error response code indicates that the server, while acting as a gateway or proxy, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found