uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.76k stars 563 forks source link

How to proxy with uWebsocket.js #952

Closed JemiloII closed 1 year ago

JemiloII commented 1 year ago

So I love using uWebsockets.js for the websockets part, but I recently found out that mobile networks suck. They seem to only allow websockets on select ports. Your mileage may vary with your carrier. Anyways, since bun.js isn't natively supported for windows yet, not a fan of wsl2, looking to use uWebsockets to proxy my express.js application as I convert it over. What is the best way of doing this with uWebsockets so the client shares a single port?

uNetworkingAB commented 1 year ago

I don't understand. But in any case - that doesn't sound right. Your carrier cannot know what type of web protocols you are using, esp. not with TLS.

JemiloII commented 1 year ago

My websocket is using port 8443, mobile networks only want 443, which is currently in use by my express server. I don't control the mobile networks and what they allow, if I could, well :)

e3dio commented 1 year ago

They seem to only allow websockets on select ports

It's more accurate to say "they don't allow TCP on select ports" not just websockets

How to proxy with uWebsocket.js

Use fetch() to forward the request, this does not require an open issue. Or better don't waste time with that and remove the proxy and express and respond with uWS.js

markg85 commented 1 year ago

My websocket is using port 8443, mobile networks only want 443, which is currently in use by my express server. I don't control the mobile networks and what they allow, if I could, well :)

Hmm, curious.

Why did you set it up this way? You're asking for trouble when using different ports. You should just setup your site on port 443 with websockets included. It's the browser part that does the handover from `wss:// to the websocket port and following that route it likely will just work on your carrier.

Personally i'm running sites on just the regular ports with websockets behind the scenes too.

Regardless of what you do, try and run it on a localhost environment (on port 80) and see if that works normally. If that does then step it up to your server and 443 (or whatever other custom port you want), it should just work provided you setup the certificates.

JemiloII commented 1 year ago

Use fetch() to forward the request, this does not require an open issue. Or better don't waste time with that and remove the proxy and express and respond with uWS.js

I don't feel like you even read what I have posted. I want to proxy so I don't have to rewrite every service at once. Also, removing the cloudflare proxy layer is not an option. It helps with image caching and mitigates ddos attacks.

Using fetch just doesn't seem right. I was trying to avoid having to setup a proxy server. Thought with how fast uws is, a proxy would be a simple task for it as I migrated over. I'm just one person working on this project and have too many services to just have a weekend project to convert them.

uNetworkingAB commented 1 year ago

uWS is not a proxy and not a stand-alone product. There are such projects already widely available.