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

    Larry

    03/01/2022, 5:04 PM
    What does it do if you add a
    [[path]].js
    or
    [[path]].ts
    file in the
    ./functions
    folder? Based upon this, I'm guessing that might then serve as your catch all: https://developers.cloudflare.com/pages/platform/functions/#functions-routing
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 5:04 PM
    Yeah, so it's kind of like a Worker? But it doesn't actually bypass static asset serving. What happens (SvelteKit specific) internally is that, on build, your
    _worker.js
    compiles a list of all of the static assets (like images, text files, etc) then on request it matches the request to that list and if it's a match it forwards it to Pages so that the static file is still served.
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 5:04 PM
    Static files aren't bundled into the
    _worker.js
    .
  • l

    Larry

    03/01/2022, 5:05 PM
    You'd have to make sure it handled 404s and maybe even static assets though. I haven't tried it. If you can isolate those routes, maybe you could put them all under
    ./functions/handle-special/[[path]].js
    ?
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 5:06 PM
    Also, in my mind it's still a Function since it gets the inputs that are Pages specific, even if it lacks file-system routing.
  • l

    Larry

    03/01/2022, 5:06 PM
    Another idea is to try doing what you need with middleware but I haven't tried that either: https://developers.cloudflare.com/pages/platform/functions/#adding-middleware
  • l

    Larry

    03/01/2022, 5:18 PM
    Ohh, I didn't know that. What inputs are Pages specific?
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 5:19 PM
    Haha, disregard that, I was thinking of regular Functions (non
    _worker.js
    ) which get a
    next
    that allows easier forwarding to the static file.
  • l

    Larry

    03/01/2022, 5:26 PM
    That brings me full circle, except with more confidence. SvelteKit with
    adapter-cloudflare
    is not really using Pages Functions. Just Pages. 🙂
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 5:27 PM
    Well, if you want to get into the technical details, even static Pages is actually Workers, so. 😆
  • m

    mibaatwork

    03/01/2022, 6:03 PM
    Hi Larry. your explanation is not correct. if you use the /functions folder in a SvelteKit project, Cloudflare Pages ignores the Svelte app's .sveltekit/cloudflare/_worker.js entry point. I had already described this above. Also a possible solution (but here the developers of Cloudflare would have to do something.
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 6:07 PM
    No, it's not a possible solution because of the architecture.
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 6:07 PM
    When you use a
    /functions
    folder Pages actually bundles it into a single
    _worker.js
    for you, you just aren't aware.
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 6:07 PM
    So using both a
    _worker.js
    and
    /functions
    would never be able to work.
  • m

    mibaatwork

    03/01/2022, 6:11 PM
    well, if it's wrapped in a _worker.js anyway, Clouflare could combine both _worker.js when using the framework preset for Svelekit.
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 6:12 PM
    Not really, that's not how bundling works. There's a router built into Cloudflare's
    _worker.js
    when using
    /functions
    and also a completely different router for SvelteKit's
    _worker.js
    that aren't compatible when used together.
  • m

    mibaatwork

    03/01/2022, 6:19 PM
    how about the other way around? if @sveltejs/adapter-cloudflare looks at the bundle if there is a function folder included and integrates the endpoints into the svelte worker?
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 6:20 PM
    The APIs are very different; while it might be possible it's highly unlikely to ever work. I would instead urge you to use Endpoints; anything you can do in
    /functions
    you can do in Endpoints.
  • m

    mibaatwork

    03/01/2022, 6:23 PM
    yes, i have also stayed away from it. i now use other independent workers that have written in rust and call them from the svelt app. is also ok!
  • l

    Larry

    03/01/2022, 7:59 PM
    If the generated
    _worker.js
    from SvelteKit is going to be ignored, why not use
    adapter-static
    instead of
    adapter-cloudflare
    ?
  • d

    Deleted User

    03/01/2022, 8:06 PM
    the location data from the
    cf
    object is invaluable. you can create really localized content. I wonder why this strategy isn't more prevalent
  • l

    Larry

    03/01/2022, 8:39 PM
    Where is the
    cf
    object?
  • k

    kian

    03/01/2022, 8:41 PM
    Should be under the request passed from the fetch handler - at least it is in a traditional worker
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 8:59 PM
    CF is on
    context.request
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 8:59 PM
    (It's not standard, if you want typing information you'll need to use Cloudflare's types, forgot what they're called exactly)
  • w

    Walshy | Pages

    03/01/2022, 8:59 PM
    workers-types 😉
  • a

    adam

    03/01/2022, 10:15 PM
    that'd work if everything I needed to handle was behind a
    /api
    , but I have a couple routes that are directly at the root, so I don't want to use a catch all. Vercel for example allows you to use a regex
  • a

    adamdbradley

    03/02/2022, 12:10 AM
    I see it's been asked a few times, but can't seem to figure out the correct way to see any logs from functions. Is it currently not possible?
  • j

    James

    03/02/2022, 12:34 AM
    Not in production at this time unfortunately, sorry! It's definitely coming for when Functions hits GA though
  • j

    James

    03/02/2022, 12:34 AM
    For now, I believe your only option is to use wrangler2 and debug locally
1...878889...392Latest