Cloudflare workers not working on custom domain

Hi,
I’m having a problem for almost quite a bit of time now. I have two API endpoints and two of them sends requests to sendgrid and mailchimp, fairly simple API. I get the request, I extract data from request body and sends that to their respect providers.

I tried it in my local environment, it is working fine. I deployed it, it works the same with worker.dev URL but not with custom domain. But it used to work 2-3 months ago. It was working great until I saw it was throwing errors. The errors are weird in custom domain. In sendgrid endpoint, it never finishes an if statement, then in mailchimp endpoint, it throws error and so on. But it works in workers.dev environment.

Another thing is, it used to work in custom domain as I said 2-3 months ago and now I am totally confused. I tried a few ways to fix it, I made changes in the code, it doesn’t work. I changed how the custom domain work, still the same problem. Previously, I used to add CNAME record of nameservers and proxy it, now it doesn’t work and still shows those weird errors. So I tried this method, Custom domain for workers? - #4 by pier. Still it doesn’t work. And now I don’t know what to do!

Could you share what the error is? I suggest tailing the output (“Logs” in your Worker) and triggering it. This will give us the most insight into what is happening

This is the log where the API failed,

"outcome": "ok",
  "scriptName": null,
  "exceptions": [],
  "logs": [],
  "eventTimestamp": 1632838205228,
  "event": {
    "request": {
      "url": "https://api.raiyansarker.com/v1/email",
      "method": "POST",
      "headers": {
        "accept": "*/*",
        "accept-encoding": "gzip",
        "cf-connecting-ip": "103.67.156.151",
        "cf-ipcountry": "BD",
        "cf-ray": "695d8d9c2b3d4aa7",
        "cf-visitor": "{\"scheme\":\"https\"}",
        "connection": "Keep-Alive",
        "content-length": "242",
        "content-type": "application/json",
        "host": "api.raiyansarker.com",
        "postman-token": "REDACTED",
        "user-agent": "PostmanRuntime/7.28.4",
        "x-forwarded-proto": "https",
        "x-real-ip": "103.67.156.151"
      },
      "cf": {
        "clientTcpRtt": 196,
        "longitude": "90.38200",
        "latitude": "23.74600",
        "tlsCipher": "AEAD-AES128-GCM-SHA256",
        "continent": "AS",
        "asn": 45245,
        "clientAcceptEncoding": "gzip, deflate, br",
        "country": "BD",
        "tlsClientAuth": {
          "certIssuerDNLegacy": "",
          "certIssuerSKI": "",
          "certSubjectDNRFC2253": "",
          "certSubjectDNLegacy": "",
          "certFingerprintSHA256": "",
          "certNotBefore": "",
          "certSKI": "",
          "certSerial": "",
          "certIssuerDN": "",
          "certVerified": "NONE",
          "certNotAfter": "",
          "certSubjectDN": "",
          "certPresented": "0",
          "certRevoked": "0",
          "certIssuerSerial": "",
          "certIssuerDNRFC2253": "",
          "certFingerprintSHA1": ""
        },
        "tlsExportedAuthenticator": {
          "clientFinished": "29bfd7f2e02706164dca4b7c0e68ddc966e9e3ff4f4df402a68d96e0ed645c7a",
          "clientHandshake": "b8b0e6472d43a2830a4c55735e7aba3b1b2d6a590a73ab25b163d87ad67ed339",
          "serverHandshake": "a9bf4121982879ed1cef93639787f0e22c968469cb5fa8d6d11d2eb4dee55e24",
          "serverFinished": "f5593fa4e53c2c89cbee53cab84eb2cfa4743e4dd5030431b4c640b2ac70da93"
        },
        "tlsVersion": "TLSv1.3",
        "colo": "SIN",
        "timezone": "Asia/Dhaka",
        "city": "Dhaka",
        "edgeRequestKeepAliveStatus": 1,
        "requestPriority": "",
        "httpProtocol": "HTTP/1.1",
        "region": "Dhaka Division",
        "regionCode": "C",
        "asOrganization": "Banglalink",
        "postalCode": "1205"
      }
    }
  },
  "id": 0

Same codebase, but workers.dev url which gave successful response

 "outcome": "ok",
  "scriptName": null,
  "exceptions": [],
  "logs": [],
  "eventTimestamp": 1632838233475,
  "event": {
    "request": {
      "url": "https://api-raiyansarker-backend.raiyan.workers.dev/v1/email",
      "method": "POST",
      "headers": {
        "accept": "*/*",
        "accept-encoding": "gzip",
        "cf-connecting-ip": "103.67.156.151",
        "cf-ipcountry": "BD",
        "cf-ray": "695d8e4f1c576c7d",
        "cf-visitor": "{\"scheme\":\"https\"}",
        "connection": "Keep-Alive",
        "content-length": "242",
        "content-type": "application/json",
        "host": "api-raiyansarker-backend.raiyan.workers.dev",
        "postman-token": "REDACTED",
        "user-agent": "PostmanRuntime/7.28.4",
        "x-forwarded-proto": "https",
        "x-real-ip": "103.67.156.151"
      },
      "cf": {
        "clientTcpRtt": 378,
        "longitude": "90.38200",
        "latitude": "23.74600",
        "tlsCipher": "AEAD-AES128-GCM-SHA256",
        "continent": "AS",
        "asn": 45245,
        "clientAcceptEncoding": "gzip, deflate, br",
        "country": "BD",
        "tlsClientAuth": {
          "certIssuerDNLegacy": "",
          "certIssuerSKI": "",
          "certSubjectDNRFC2253": "",
          "certSubjectDNLegacy": "",
          "certFingerprintSHA256": "",
          "certNotBefore": "",
          "certSKI": "",
          "certSerial": "",
          "certIssuerDN": "",
          "certVerified": "NONE",
          "certNotAfter": "",
          "certSubjectDN": "",
          "certPresented": "0",
          "certRevoked": "0",
          "certIssuerSerial": "",
          "certIssuerDNRFC2253": "",
          "certFingerprintSHA1": ""
        },
        "tlsExportedAuthenticator": {
          "clientFinished": "7a50c6e0ed492d353d6fbb68b1f8af44893ddfe039e15461301cac608ba2dd57",
          "clientHandshake": "89affa53d6df9f1e252b34673d18278f7f6b122191e93f7f45cbaaa049091efd",
          "serverHandshake": "a1879944130aaae4f1cba6514508b5537904a19b17873bddc4b7d81a5c55f5ab",
          "serverFinished": "610544bc4fa829f5308adbe1907942d1f00b40def4ace0506f422fa9da6f6040"
        },
        "tlsVersion": "TLSv1.3",
        "colo": "SIN",
        "timezone": "Asia/Dhaka",
        "city": "Dhaka",
        "edgeRequestKeepAliveStatus": 1,
        "requestPriority": "",
        "httpProtocol": "HTTP/1.1",
        "region": "Dhaka Division",
        "regionCode": "C",
        "asOrganization": "Banglalink",
        "postalCode": "1205"
      }
    }
  },
  "id": 1