https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • b

    bret_pat

    04/14/2023, 5:59 AM
    How can I trigger a cloudflare worker from a non-cloudflare backend? Can I enqueue a message from a non cloudflare worker as well?
  • h

    HardAtWork

    04/14/2023, 6:01 AM
    Just send an HTTP request?
  • b

    bret_pat

    04/14/2023, 6:03 AM
    In that scenario, I would be responsible for creating my own means of authenticating the request.
  • b

    bret_pat

    04/14/2023, 6:04 AM
    But gotcha. I guess I was just wondering if there was a client library of some sort or not
  • h

    HardAtWork

    04/14/2023, 6:05 AM
    Not really, because any HTTP(S) request hitting a route covered by a Worker will run said Worker
  • h

    HardAtWork

    04/14/2023, 6:06 AM
    There isn’t really anything there for the library to do
  • h

    HardAtWork

    04/14/2023, 6:06 AM
    At least not with just a regular Worker
  • h

    HardAtWork

    04/14/2023, 6:07 AM
    If you are running a GraphQL server on Workers, then there are a few libs to choose from there
  • j

    johannes

    04/14/2023, 6:17 AM
    Hey folks, here's something that kept me up all night: I'm making a request to a db running on my server from within a worker. Running it locally works fine, but fails once it's deployed. I've been looking at the access logs on the server and the requests coming from the deployed worker seem off: (worker on CF):
    "GET /api/health HTTP/1.1" 404 19 "-" "-" 331 "-" "-" 0ms
    (worker running locally):
    "GET /api/health HTTP/1.1" 200 41 "-" "-" 355 "pb1@docker" "http://172.24.0.5:8090" 1ms
    I notice that all the requests initiated from the deployed worker (even those with a body etc) all have only
    19 bytes
    request size. It's a long shot, but what are your thoughts on that?
  • k

    kian

    04/14/2023, 6:20 AM
    Are you fetching an IP and/or on a non-standard port?
  • k

    kian

    04/14/2023, 6:20 AM
    If not, would need to see what the
    fetch
    code looks like
  • j

    johannes

    04/14/2023, 6:25 AM
    Just your vanilla fetch:
    Copy code
    const x = await fetch("https://db-dev.textmait.se/api/health");
    console.log("Health", x.status);
  • j

    johannes

    04/14/2023, 6:25 AM
    I already had the thought that it could have something to do with maybe certificates, but I guess then the request would fail in a different way?
  • j

    johannes

    04/14/2023, 6:28 AM
    The thing that throws me off is that my reverse proxy (traefik) is the one returning the 404, it doesn't seem to be able to route it to the right docker container. So it's either an issue with the rev. proxy (traefik), or it's an issue with the request itself (cloudflare)
  • j

    johannes

    04/14/2023, 6:36 AM
    Okay, just deployed a minimal example, and here the requests are fine (result and server logs). Must be something with the deployment config of the other worker.
  • j

    johannes

    04/14/2023, 6:40 AM
    Update: It's a Cloudflare issue with custom domains. As soon as I add
    route = { pattern = "api2.textmait.se", custom_domain = true, zone_id = "xxx" }
    to my wrangler config, the requests fail. Any pointers to how my config is wrong?
  • k

    kian

    04/14/2023, 6:42 AM
    Is the Worker you're fetching from also on
    textmait.se?
  • k

    kian

    04/14/2023, 6:42 AM
    Same-zone subrequests are, uh, annoying
  • j

    johannes

    04/14/2023, 6:43 AM
    Yup,
    db-dev.textmait.se
    is an A record pointing to my server,
    api2.textmait.se
    is managed by CF to point to the worker.
  • k

    kian

    04/14/2023, 6:43 AM
    Add
    Copy code
    toml
    # https://github.com/cloudflare/workers-sdk/issues/2659
    compatibility_flags = ["no_minimal_subrequests"]
    to your wrangler.toml
  • k

    kian

    04/14/2023, 6:44 AM
    you can track that issue to know when you can remove the compatibility flag
  • j

    johannes

    04/14/2023, 6:47 AM
    Thank you! What exactly does this do? Because I'm not seeing any changes after deploying with it
  • k

    kian

    04/14/2023, 6:47 AM
    No idea - it's just what the Workers team recommend in that linked issue which supposedly fixes the same-zone subrequests
  • j

    johannes

    04/14/2023, 6:50 AM
    Huh, okay. Tbh, never heard about same-zone subrequests until now, so I'll keep that in mind. I've at least now have our service back and running by using the .workers.dev domain, so thank you very much for pointing me into the right direction!
  • k

    kian

    04/14/2023, 6:50 AM
    Historically, a Worker on
    foo.com
    has never been able to fetch anything else on
    foo.com
  • k

    kian

    04/14/2023, 6:50 AM
    Using a custom domain (rather than a route) allowed it to fetch other things on
    foo.com
  • k

    kian

    04/14/2023, 6:50 AM
    but then
    minimal_subrequests
    (default as of
    2022-04-05
    ) broke that
  • j

    johannes

    04/14/2023, 6:51 AM
    Wow that's fascinating. I think I wouldn't have been able to figure that out by myself
  • j

    johannes

    04/14/2023, 6:51 AM
    Worst case I gotta buy a second domain for the api 😅
  • k

    kian

    04/14/2023, 6:51 AM
    It really should just work - comment on that it's still broken for you and the team might have other suggestions
1...239323942395...2509Latest