I am trying to make HTTP requests from my Cloudflare Worker to a backend service that is only available via IP address (no domain name):
The same call works over CURL, but from my Worker I get a 1003 Error.
- I tried using
fetchand get blocked - I tried using Node's http module with
nodejs_compatand getting: [unenv] http.request is not implemented yet!" - When I try to make the call directly from the Frontend (my html file), I get a mixed content error because my site is served over https but the backend is http.
Question: What's the recommended way to make HTTP requests to an IP address from a Worker when a domain name isn't available? Is there a way to bypass the IP address restriction, or should I be looking at a different architecture?
app.post("/api/orders", async (c) => {
try {
const body = await c.req.json();
const response = await fetch("http://xx.xxx.xx.xxx/orders", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body)
});
// ... handle response
} catch (error) {
return c.json({ error: 'Failed to process order' }, 500);
}
});