Fetch ignoring port
See original GitHub issue🐛 Bug Report
I’m having an extremely strange issue where Fetch() completely ignores any custom port when actually running in the deployed Worker but from the quick editor, it works as expected.
I’ve gotten the Worker as simplified as much as possible to try and debug this issue. To explain the test, I have Nginx running on 443 and another application on 4567.
Steps to reproduce
addEventListener('fetch', event => {
event.respondWith(rewriteURL(event.request))
})
async function rewriteURL(request) {
let urlWithPort = new URL("https://test.file.properties:4567/download/file")
urlWithPort.port = 9055
//return new Response(urlWithPort) - shows the port 9055 in the URL, as it should.
const response = await fetch(urlWithPort, request)
return response
}
What did you expect to see?
- When I test this code from the quick editor, I get 502 (expected) because I specified port 9055 and it’s using that as I told it to
- When I test this code by visiting the deployed URL, I get an Nginx 404 page (so it’s completely ignoring port 9055)
- If you change
urlWithPort.port
to 4567 (or remove it), the quick editor will successfully return it from the application running on port 4567 (expect some JSON error about processing the request because the application expects some headers and parameters)
I’m expecting the deployed Worker to use the custom specified port when doing Fetch() just like it does on the quick editor.
– Wrangler wasn’t used to create this worker, so I didn’t specify any environment. I’ve entirely used the online quick editor.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
ES6 fetch: How do I change the localhost port it calls?
Have you tried to put full url in your fetch first parameter? Pretty sure /api/login would make the request to the current host....
Read more >On fetch method post https, any port different of 443 is ignored
When calling "fetch" with "post" method and "https", the port will be always 443, even if you try to use a different port....
Read more >Fetch in Workers does not work with non standard ports
This is because Cloudflare is constantly ignoring the port and always accessing the server from port 443, thus always getting a redirect to...
Read more >Fetch: Cross-Origin Requests - The Modern JavaScript Tutorial
Cross-origin requests – those sent to another domain (even a subdomain) or protocol or port – require special headers from the remote side....
Read more >Fetch Standard
If url 's scheme is an HTTP(S) scheme and url 's port is a bad port, ... The user agent may either accept...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let’s leave this open till we ship a fix in the runtime
Whoops, reopening