Need help about Direct IP access not allowed

I’m trying to use workers to be a reverse proxy to proxy traffic to my real ip backend. which can help me to hide my server ip. the code looks like this.

export default {
  async fetch(request) {
    const url = new URL("http://{my ip}");
    url.pathname = new URL(request.url).pathname;

    const newRequestInit = {
    };

    const newRequest = new Request(
      url.toString(),
      new Request(request, newRequestInit)
    );

    return await fetch(newRequest);
}
}

however, when I test in edit mode, it works. but when i try to access it from the auto generate link from my worker, it says Direct IP access not allowed. I don’t understand, i’m accessing by url, why it’s 1003. how can i solve this.

Workers can only fetch domains, not IPs (i.e create an A DNS Record for {your ip} like backend.example.com and fetch that). The different behavior in Preview is weird, but the end result is e expected.

1 Like