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
There's a handy flowchart for subrequest ports that a community mvp made:
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)
Im just trying to do a PUT resquet to an api that has that port
If that "API" isn't on the same zone as your worker is executing, CF will default to 80/443 for http/https respectively
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
If api.com was your zone/website added within CF, your worker would have to be executing on api.com as well
api.com is a third party api
is not hosted on CFW
then I don't think there's anyway, that I know of, that you can make that work
so there is no way to fix this:
No you cannot use custom ports unless its your domain
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
You can use fetch but it wont go to a custom port
it will go to :443
I see
And isn’t there another way besides fetch to run that request?
Like curl or something
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/
Youre going to have to use a proxy of some sort via another server
I see
And how would you recommend I do that?
many different ways 🤷 aws lambda, digital ocean functions, an actual vps
Okay
Thanks!