'Create react app proxy doesn't redirect request
I have created react app with create-react-app
So the backed server listens on port 5000. The react server listens on port 3000.
I added this line "proxy": "http://localhost:5000" to package JSON.
Now when I do a request like this:
GET /api/hello HTTP/1.1
Host: 192.168.0.102
Content-Type: application/json
to the react app. I get this message:
+IPD,420:HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Security-Policy: default-src 'self'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 148
Vary: Accept-Encoding
Date: Sat, 03 Nov 2018 11:18:11 GMT
Connection: keep-alive
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /api/hello</pre>
</body>
</html>
This is a link to the proj files : https://github.com/RadoslavMarinov/stack-show
Solution 1:[1]
Sorry I found the mistake I have made. I misunderstood the create-react-app documentation.
It says:
Any unrecognized request without a
text/html accept headerwill be redirected to the specified proxy.
Instead of putting Accept: application/json in the request header I put Content-Type: application/json. Which is wrong.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hairi |
