https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • h

    HardAtWork

    04/28/2023, 4:13 PM
    This error occurs because you shouldn't be direct-accessing the origin(Pages), using Functions, because then it would be calling itself. Instead, you can do this:
    Copy code
    ts
    export const onRequest: PagesFunction = async ({ request, next }) => {
        const response = await next();
    
        // Clone the response so that it's no longer immutable
        const newResponse = new Response(response.body, response);
    
        // Add a custom header with a value
        newResponse.headers.append(
          "x-workers-hello",
          "Hello from Cloudflare Workers"
        );
    
        return newResponse;
    }
  • l

    Lloyd

    04/28/2023, 4:14 PM
    Is that documented? I've found this to be a pretty withering on boarding experience...
  • l

    Lloyd

    04/28/2023, 4:14 PM
    ill give that a go, thanks
  • h

    HardAtWork

    04/28/2023, 4:15 PM
    Documented [here](https://developers.cloudflare.com/pages/platform/functions/api-reference/), and in the types for
    PagesFunction
    too.
  • l

    Lloyd

    04/28/2023, 4:15 PM
    I mean using fetch causing some kind of redirect loop
  • s

    Skye

    04/28/2023, 4:16 PM
    That error message is really weird, I agree it's confusing
  • s

    Skye

    04/28/2023, 4:16 PM
    @Walshy | Pages do you know how easy that is to change?
  • h

    HardAtWork

    04/28/2023, 4:17 PM
    It's more a Workers thing. It happens because if a Worker covers the domain https://hello.pages.dev, and that Worker makes a request to https://hello.pages.dev. That error appears to prevent it from just infinitely trying to fetch itself.
  • l

    Lloyd

    04/28/2023, 4:17 PM
    I keep seeing that functions and workers are 99% overlap except for when you find an example worker that seems like it should work but then it doesnt... like how using fetch does this
  • c

    Chaika

    04/28/2023, 4:18 PM
    (You can do fetch like that if the worker is on a route over an existing origin, to fetch the origin under it, but not in Pages)
  • w

    Walshy | Pages

    04/28/2023, 4:18 PM
    hi what
  • l

    Lloyd

    04/28/2023, 4:18 PM
    sometimes next is awaited, sometimes its not, sometimes its at the top, sometimes its at the bottom...
  • h

    HardAtWork

    04/28/2023, 4:18 PM
    That's just standard Promise stuff. If you are just returning an Asynchronous Function, then you don't need to await it.
  • s

    Skye

    04/28/2023, 4:18 PM
    Request loop error message is weird https://canary.discord.com/channels/595317990191398933/910978223968518144/1101541068853477437
  • l

    Lloyd

    04/28/2023, 4:20 PM
    Yeah, but what I don't see documented is how the worker/function framework handles promises - what does it mean from an end developers point of view if they return a promise at the top or the bottom of their code for example
  • h

    HardAtWork

    04/28/2023, 4:20 PM
    But basically,
    next()
    means
    fetch()
    the next Function or static asset. So if you need the Response at the beginning of the Function, you call
    next()
    first. If you want it as a fallback, you call
    next()
    last.
  • h

    HardAtWork

    04/28/2023, 4:20 PM
    You call it when you need it
  • h

    HardAtWork

    04/28/2023, 4:21 PM
    Think of it as a replacement for
    fetch(request)
  • w

    Walshy | Pages

    04/28/2023, 4:30 PM
    not sure how it actually hit that without tracing, it should only hit that if it goes to pingora with a CF IP
  • w

    Walshy | Pages

    04/28/2023, 4:30 PM
    if it was 100::, it should 522
  • s

    Skye

    04/28/2023, 4:30 PM
    trace it then
  • s

    spacey

    04/28/2023, 4:38 PM
    as i understand an app with cloudflare page functions cannot be a queue consumer you have to setup an entirely separate worker as a consumer this means in dev you have to run both and they don't share a queue so no way to test and end to end flow
  • s

    spacey

    04/28/2023, 5:28 PM
    the bindings i defined in wrangler.toml for d1 and queues don't show up in the
    settings/functions
    web ui. do i have to manually add these bindings i through wrangler.toml configured it automatically?
  • s

    spacey

    04/28/2023, 6:07 PM
    I'm building a simple pages function using
    hono
    and
    workers-qb
    it add a user row to id and sends the same data to queues. this works in dev (minus queues) however when deployed i'm getting a 500 with
    RangeError: Maximum call stack size exceeded
  • s

    spacey

    04/28/2023, 6:21 PM
    I want to say thank you toe everyone here who tried to help. However the dev flow for cloudflare page functions + d1/kv/queues is terrible. i'm going to say a small function writing to a db or a queue should not be rocket science but after reading all the docs and struggling for multiple days i'm almost at giving up. the ideas around this product are really great but i hope the product teams recognize the giant ux issue here roadmap it. i'm not a novice at building this stuff just wanted to experiment with the idea of edge compute instead of going cloudrun/fargate etc.
  • z

    zszszsz

    04/28/2023, 9:48 PM
    That is the known issue I guess
  • z

    zszszsz

    04/28/2023, 9:49 PM
    That's why d1 and queues are alpha/beta things.
  • l

    Lloyd

    04/28/2023, 9:55 PM
    similar feelings with the thing i mentioned above
  • s

    spacey

    04/28/2023, 10:07 PM
    alpha/beta cannot be that it does not work it i never said i need it to be production grade with an sla all i ask for it to see the flow working.
  • s

    spacey

    04/28/2023, 10:09 PM
    also if there are glaring holes in the flow then don't throw it over the wall on the main website with an "beta" tag it endsup wasting customers time.
1...378379380...392Latest