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

    Marcelino Franchini

    11/27/2021, 1:50 AM
    If you only need to redirect you can use the refresh header to save function executions: https://example.pages.dev/* Refresh: 0; url=https://example.com/:splat
  • t

    The Freelancer ;)

    11/27/2021, 1:50 AM
    lol
  • r

    ReaverCelty

    11/27/2021, 4:43 AM
    Is there any way to fetch log files? Wrangler tail doesn't seems to say it cant find my script
  • e

    Erwin

    11/27/2021, 4:47 AM
    Do you wrangler publish to publish that same script?
  • r

    ReaverCelty

    11/27/2021, 4:53 AM
    I did not (was not aware it would deploy into pages)
  • w

    Walshy | Pages

    11/27/2021, 5:02 AM
    You cannot tail Functions right now
  • r

    ReaverCelty

    11/27/2021, 5:04 AM
    Ok, I'll just sleep on it then. Thanks Walshy
  • e

    Erwin

    11/27/2021, 5:20 AM
    Oh doh.. sorry, I didn't see this was the Pages Function channel.. yeah, nah. That is what I am currently running into as well right now. And somehow my error handler doesn't seem to work either..
  • e

    Erwin

    11/27/2021, 5:38 AM
    You should be able to run your functions locally with
    npx wrangler@beta pages dev
    and then specify the build directory
  • m

    Marcelino Franchini

    11/27/2021, 2:39 PM
    Someone was able to call the image resizing via fetch() on a Pages Functions? It's enabled? https://developers.cloudflare.com/images/image-resizing/resize-with-workers
  • m

    Marcelino Franchini

    11/27/2021, 2:40 PM
    What is the proper debugging experience for Cloudflare Pages Functions? I am getting 1101 errors of workers exceptions and I don't know where to look to understand the problem.
  • w

    Walshy | Pages

    11/27/2021, 2:40 PM
    Image Resizing doesn't work with Functions right now but the team is aware
  • w

    Walshy | Pages

    11/27/2021, 2:41 PM
    and testing locally is the easiest way or surrounding the code in a try catch printing the exception
  • r

    ReaverCelty

    11/27/2021, 6:05 PM
    Yep, I just cant get it to work on local 😛 lol, i originally was in #799437470004412476 but kinda hit a dead end there
  • t

    Tim

    11/28/2021, 1:29 AM
    is KV the only way to handle cookie sessions?
  • j

    johanndev

    11/28/2021, 10:48 AM
    Hi! I'm struggling to get the most basic pages/function project working on my machine, can somebody take a look? https://github.com/cloudflare/wrangler2/issues/50 My worker script seems to be ignored by wrangler 🤔
  • r

    rkusa

    11/28/2021, 12:42 PM
    Am I right to assume that support for WASM will be added (to plinko) in the future?
  • r

    rkusa

    11/28/2021, 3:27 PM
    Is it possible that
    waitUntil
    inside of pages functions is broken? I am receiving a
    Illegal invocation
    both in miniflare and deployed. Looking at miniflare's code made me beliefe that I shouldn't deconstruct the context (
    onRequest({ctx})
    ), but I get the same error with
    ctx.waitUntil
    .
  • v

    Vinsg

    11/28/2021, 4:40 PM
    It works fine on my end when using the url served by wrangler. Try using the url
    Copy code
    Serving at http://127.0.0.1:[[your port]]
    from the console output.
  • j

    johanndev

    11/28/2021, 4:55 PM
    Figured it out - I should have paid more attention to the CLI output 🙂 When serving a static directory, the
    --port
    switch is not optional - when I provide a proxy-port, everything works as expected:
    Copy code
    npx wrangler@beta pages dev --proxy 3000 --local ./static
  • s

    simplenotezy

    11/28/2021, 8:02 PM
    Hey there! I'd like to make a Cloudflare Pages function, that simply returns the CF_PAGES_COMMIT_SHA - is this possible? I tried with process.env.CF_PAGES_COMMIT_SHA but it complains process is not defined. I am trying now with simply CF_PAGES_COMMIT_SHA but I am getting a notion this variable only will be available during build?
  • r

    rkusa

    11/28/2021, 8:42 PM
    Yes, only available during build (AFAIK). I solved it by having this script as part of the build:
    Copy code
    json
    "build:version": "echo \"{ \\\"rev\\\": \\\"${CF_PAGES_COMMIT_SHA:=dev}\\\" }\" > worker/version.json",
    and import it in my worker/function via
    Copy code
    ts
    import version from "../worker/version.json";
    // version.rev gives you CF_PAGES_COMMIT_SHA
  • s

    simplenotezy

    11/28/2021, 8:47 PM
    Nice workaround @User . I just did something very similar, instead part of my build step (npm run build) I'll use
    fx.writeFile
    to write the version number to a file.
  • s

    simplenotezy

    11/28/2021, 8:47 PM
    thanks for sharing!
  • j

    johanndev

    11/28/2021, 9:07 PM
    After getting over the first hurdles, I'm stuck on another frontier: Function routing. I created a folder/file structure as described in: https://developers.cloudflare.com/pages/platform/functions#functions-routing. All files contain the same request handler, which just returns the physical path to the respective worker script:
    Copy code
    export async function onRequestGet(context) {
        return new Response("Hello from <path/to/worker>");
    }
    and tried to call these paths: http://localhost:8788/api/todos http://localhost:8788/api/todos/1 http://localhost:8788/api/todos/1/edit http://localhost:8788/foo/profile http://localhost:8788/api/my/custom/path All of these paths return the index.html page from my vue app and don't invoke the respective worker. If I however place an
    index.ts
    with the same code at
    ./functions/index.ts
    , the route
    http://localhost:8788
    works and returns the expected response! What am I missing ? :/ Opened an issue on github: https://github.com/cloudflare/wrangler2/issues/58
  • j

    Jeremiahlee

    11/28/2021, 9:22 PM
    I want to do this:
    Copy code
    addEventListener("fetch", (event) => {
        event.passThroughOnException();
        event.respondWith(handleRequest(event));
    });
    in a Pages Function, but I get this error:
    Global addEventListener() cannot be used in modules. Instead, event handlers should be declared as exports on the root module.
    and I don't know what to do with that. Any pointers?
  • w

    Walshy | Pages

    11/28/2021, 9:23 PM
    Functions don't need the listener. Instead they have a different input:
    Copy code
    js
    export async function onRequest(context) {
      return new Response("Hello, world!");
    }
  • j

    Jeremiahlee

    11/28/2021, 9:24 PM
    This is a listener on
    fetch
    for when my function makes a
    fetch
    request, not the request triggering the function.
  • w

    Walshy | Pages

    11/28/2021, 9:26 PM
    You can't listen to yourself making a fetch, what're you trying to do exactly?
  • j

    Jeremiahlee

    11/28/2021, 9:27 PM
    I'm trying to retrieve a file / forward a POST to another origin and proxy it through.
1...222324...392Latest