I have the following worker deployed:
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
return fetch("http://test.example.com:9000")
}
Note: The actual domain is not example.com, I am just using it for illustrative purposes.
test.example.com:9000
is not served over https and is running on a vps that I control. The example.com domain is pointed to Cloudflare, and the test.example.com has an A record pointing to the IP address of the vps with proxying (orange cloud) turned off.
Using the browser on my own machine, I am able to visit http://test.example.com:9000 successfully. I am also able to visit it using the ip address of the server: http://192.168.1.1:9000 (note: this is not the actual ip, it’s just for illustrative purposes).
However, if I use fetch in my worker to fetch the ip address, it returns the 1003 error code, saying that it can’t fetch from the ip address. Is there any technical reason why a worker cannot fetch from an IP address?
If I use fetch in my worker to fetch from http://test.example.com:9000
, it times out and I get a http 522 error.
Any ideas why this is happening?