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

    Isaac McFadyen | YYZ01

    02/28/2022, 9:58 PM
    Yup, I can confirm that
    wrangler.toml
    is ignored with Pages (and Functions).
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:59 PM
    With SvelteKit make sure you set either an environment variable called
    NODE_VERSION
    and a value of
    16.7.0
    , or add a file in your root folder called
    .node-version
    (no extension) with the contents of
    16.7.0
  • d

    Deleted User

    02/28/2022, 10:00 PM
    does pages + functions make workers sites obsolete? I can't imagine a reason to use workers sites
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:00 PM
    Workers Sites was the early prototype of Pages, so yes, while still supported Pages is the recommended way to go.
  • p

    Plotzes

    02/28/2022, 10:00 PM
    Maybe a bit more for advanced path handling that can't be done with the headers file yet
  • b

    balage

    02/28/2022, 10:01 PM
    alright, and about this
    @sveltejs/adapter-cloudflare
    , do I just add it to my
    svelte.config.js
    like this:
    Copy code
    js
    import adapter from '@sveltejs/adapter-cloudflare';
    
    export default {
        kit: {
            adapter: adapter()
        }
    };
    and that's it?
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:01 PM
    Yeah, but Functions could be used for that.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:01 PM
    Yup, that's it.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:01 PM
    Then choose the
    SvelteKit
    preset when creating a Pages project.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:02 PM
    And also:
    Copy code
    Make sure you set either an environment variable called NODE_VERSION and a value of 16.7.0, or add a file in your root folder called .node-version (no extension) with the contents of 16.7.0
  • b

    balage

    02/28/2022, 10:02 PM
    okay, but as I see my build folder is different here for some reason
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:03 PM
    Yeah, that's the expected build folder when building for Cloudflare.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:03 PM
    If you build locally (
    npm run build
    ) and you've got the adapter set up right you should have a
    cloudflare
    folder appear in there too.
  • b

    balage

    02/28/2022, 10:04 PM
    I haven't added the adapter to my config file yet, so maybe that's why
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:04 PM
    Yeah, that's probably why.
  • d

    Deleted User

    02/28/2022, 10:04 PM
    what causes the
    wrangler
    command to take half a second or so to run? is that node starting up?
  • b

    balage

    02/28/2022, 10:36 PM
    it worked
  • b

    balage

    02/28/2022, 10:36 PM
    this is amazing
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 10:36 PM
    👍 SvelteKit on Functions is amazing.
  • b

    balage

    02/28/2022, 10:48 PM
    how does caching work with Functions?
  • b

    balage

    02/28/2022, 10:54 PM
    is it automatic?
  • l

    Larry

    03/01/2022, 2:32 AM
    Did you mean, "SvelteKit on Pages"?
  • i

    Isaac McFadyen | YYZ01

    03/01/2022, 2:42 AM
    SvelteKit on Pages Functions, yeah. 😄
  • m

    minimusubi

    03/01/2022, 4:27 AM
    Could someone point me to the documentation for this? I tried searching the Cloudflare docs, as well as google, but could only find the mention in
  • d

    Deleted User

    03/01/2022, 4:36 AM
    @User I don't think there's very much documentation on it. https://github.com/cloudflare/workers-types/blob/74c94f8f96fa427353acd60ebc00d910f8e7cdfe/index.d.ts#L1708
  • d

    Deleted User

    03/01/2022, 4:37 AM
    you can learn a lot from https://github.com/cloudflare/images.pages.dev
  • m

    minimusubi

    03/01/2022, 6:28 AM
    Ohh, thank you for the example!
  • a

    adam

    03/01/2022, 9:17 AM
    is it (or will it be) possible to provide your own routing configuration? ie the JSON config that lives on the functions tab of a deployment:
    { "routes": { "/api": ... } }
    etc reason - don't want to use full _worker.js to handle every request, but I have a couple routes that would ideally all be handled with a single module
  • l

    Larry

    03/01/2022, 4:54 PM
    When using SvelteKit with
    adapter-cloudflare
    maybe it's still considered Cloudflare Pages Functions but it's not using the
    ./functions
    folder automation (routing, middleware, etc.). It's using SvelteKit's endpoint (not client-side UI) routing, middleware, etc. and compiling it down to an
    _worker.js
    file that seems to run as a Cloudflare worker. Yes, I know that when you use
    ./functions
    it gets compiled down to a worker also but I think of that compiling as the primary (?only?) feature of "Functions" and when using SvelteKit with
    adapter-cloudflare
    you just aren't using that feature so it's hard for me to think of that as using "Functions". Makes sense?
  • l

    Larry

    03/01/2022, 4:58 PM
    It even bypasses the serving of static assets as documented here: https://developers.cloudflare.com/pages/platform/functions/#advanced-mode
1...868788...392Latest