#Making HTTP requests to IP address from Worker

4 messages · Page 1 of 1 (latest)

dreamy hawk
#

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 fetch and get blocked
  • I tried using Node's http module with nodejs_compat and 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);
  }
});
edgy bramble
#

fetching insecure/plaintext http across the internet is a really bad idea anyway