Fetch in worker strips port number from URL

I have a worker with a simple fetch call

await fetch('https://foo.bar.com:1234/some/path', { method: 'POST', headers: {...}, body: .... });

This works fine in preview, but when deployed to production cloudflare seems to somehow strip the port number from the URL (ie the URL https://foo.bar.com/some/path is requested - which in my case is a different service).

Anybody else experiencing this? Any workaround? Where would on go and report an issue like this?

1 Like

I believe this is a known limitation, see the following resolution to the below thread.

Keep in mind the url will need to be on your Cloudflare zone (i.e. x.mysite.com) but Gray Clouded (not proxied), we don’t intend on allowing proxying to arbitrary ports on arbitrary hosts yet.

2 Likes

Is it https://foo which is requested or http:// ? If it is the latter my best guess would be Flexible could interfere here, should you have that set. What’s your encryption mode?

It’s https://... that is requested. What encryption mode do you mean?

Otherwise I would check the headers and if they have anything host/port related. What happens if you omit them altogether for a test?

I’ve tried several variations of headers I’m passing to fetch, but nothing seems to affect the outcome.

1 Like

I believe this is a known limitation, see the following resolution to the below thread.

If it’s a limitation, then it’s pretty severe one that’d deserve being called in the docs. The thread you’re referring to talks about proxying, which is not really what I’m doing - I’m basically just using fetch to retrieve some info from some APIs. If CF workers can’t be used in such a way, then I probably had the wrong expectations.

It’s also pretty misleading that the fetch requests work just fine when deploying the worker in preview mode (wrangler preview).

1 Like

This post was flagged by the community and is temporarily hidden.