Closed josejooj closed 1 year ago
Hello, so the below error seems to be uWebsockets.js
aka. hyper-express
closing the connection forcefully before the request has properly been received.
*66 upstream prematurely closed connection while reading response header from upstream, client: 170.238.13.25, server: api.dev.mywebsite.com, request: "GET /status HTTP/1.1", upstream: "http://127.0.0.1:6 3031/status", host: "api.dev.mywebsite.com"
This can only occur in the following scenarios:
fast_abort
set to true
when you constructed the Server
instance and a request with a too large content length is received.response.close()
somewhere in your code before the request's body has been retrieved.I would take the below steps to try and debug this problem further:
Server.set_not_found_handler
so that every request receives a proper response regardless of its path. You can simply return a 404 status code with whatever response body you wish or if any.cors()
middleware for now. I see that you are using the middleware twice. Once with a use()
and then with a wildcard on options()
. This would lead to the middleware running twice as use()
covers all methods automatically. But just to be on the safe side, comment out both, then gradually add each one back to see If the middleware is causing the issue.Also, can you provide to me the HTTP method, headers and body of the request you are sending to the API which gets prematurely closed by the server?
Hopefully this help : https://github.com/uNetworking/uWebSockets.js/discussions/835#discussioncomment-5369383
Ohh I see. That makes perfect sense. I also use http 1.1 in my own NGINX configurations for upstream with hyper-express hence never encountered this problem. That should solve it.
How my problem started
Hello again! I had posted about this a time ago
The post was basically about me not being able to proxy a react site to the api in hyper-express
I ended up opting for a "stop-gap solution", instead of making a proxy for the api, I just used axios and set the baseUrl as the API url, so I could make requests to the API without proxy, but the problem of not accepting requests via proxy was still there, and I thought I would have no problem with that anymore
Now, some context of my actual problem
Now I bought a VM on Google Cloud and set up a whole environment complete with nginx, below is the nginx configuration
So, what is the problem?
When I access
dev.mywebsite.com
I get the expected response from the React development serverWhen I access
api.dev.mywebsite.com
I get the502 Bad Gateway
page error from nginx, and when I open the nginx error logs I get this:2023/07/23 02:20:45 [error] 115843#115843: *66 upstream prematurely closed connection while reading response header from upstream, client: 170.238.13.25, server: api.dev.mywebsite.com, request: "GET /status HTTP/1.1", upstream: "http://127.0.0.1:6 3031/status", host: "api.dev.mywebsite.com"
But if i do a request to the API inside my VM, i get this:
And if a do the request directly by ip i receive this:
So the api is running, but not receiving proxy requests... This is my API code:
So, i want to know... What can i do to solve this? I like so much to work with hyper-express, i don't want to change to another module only for this...
OBS
- My website URL isn'tmywebsite.com
, i only don't want to share the url now, but i made the edits correctly and I think it will not affect the understanding of the question