Can't make fetch() requests to custom HTTPS port with Cloudflare Workers

Hey, I'm running into an issue with my Cloudflare Workers where I can't seem to make fetch() requests to a custom HTTPS port (not 80 or 443) on a remote server. Every time I try, I get an error message saying "connection was reset" and I can't seem to figure out what's going wrong. I've searched through the Cloudflare documentation and it looks like their network only supports HTTPS traffic on standard ports, so I'm not sure if there's anything I can do to get around this limitation. Has anyone else encountered this issue? Any tips or workarounds? I've considered using HTTP instead of HTTPS, but I'm worried about the security implications of that. I've also thought about switching hosting providers, but I really like the convenience of Cloudflare Workers. Any advice or suggestions would be greatly appreciated! Thanks in advance.
18 Replies
Chaika
Chaika2y ago
There's a handy flowchart for subrequest ports that a community mvp made:
Chaika
Chaika2y ago
I'm guessing the connection reset error is because it's defaulting to a port that you don't have open (same-zone refers to Cloudflare zones/websites, i.e a worker running on example.com connecting to an origin on cdn.example.com is same-zone)
Pato
PatoOP2y ago
Im just trying to do a PUT resquet to an api that has that port
Chaika
Chaika2y ago
If that "API" isn't on the same zone as your worker is executing, CF will default to 80/443 for http/https respectively
Pato
PatoOP2y ago
I dont think is on the same zone so what coud i do to fetch an api like this: https://demo.api.com:7024/test/test
Chaika
Chaika2y ago
If api.com was your zone/website added within CF, your worker would have to be executing on api.com as well
Pato
PatoOP2y ago
api.com is a third party api is not hosted on CFW
Chaika
Chaika2y ago
then I don't think there's anyway, that I know of, that you can make that work
Pato
PatoOP2y ago
so there is no way to fix this:
WARNING: known issue with `fetch()` requests to custom HTTPS ports in published Workers:
- https://demo.api.com:7024/test/test
- the custom port will be ignored when the Worker is published using the `wrangler publish` command.
WARNING: known issue with `fetch()` requests to custom HTTPS ports in published Workers:
- https://demo.api.com:7024/test/test
- the custom port will be ignored when the Worker is published using the `wrangler publish` command.
Unsmart
Unsmart2y ago
No you cannot use custom ports unless its your domain
Pato
PatoOP2y ago
I cant use or i cant fetch? Because i dont want to use a custom port An api that i need to use for my work has that custom port
Unsmart
Unsmart2y ago
You can use fetch but it wont go to a custom port it will go to :443
Pato
PatoOP2y ago
I see And isn’t there another way besides fetch to run that request? Like curl or something
Chaika
Chaika2y ago
Workers run on Javascript V8 Engine (same JS Engine as Chrome/Chromium) as Isolates, so the environment is browser-like. Only way you're getting a request out is via fetch. (At least for now until TCP Workers, but those are different and wouldn't really help you) https://developers.cloudflare.com/workers/learning/how-workers-works/
Unsmart
Unsmart2y ago
Youre going to have to use a proxy of some sort via another server
Pato
PatoOP2y ago
I see And how would you recommend I do that?
Unsmart
Unsmart2y ago
many different ways 🤷 aws lambda, digital ocean functions, an actual vps
Pato
PatoOP2y ago
Okay Thanks!
Want results from more Discord servers?
Add your server