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

    Isaac McFadyen | YYZ01

    02/28/2022, 9:13 PM
    Yeah.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:13 PM
    I think a lot of it is awareness as well; I see a lot of devs come through here going "wait, I did all of that work with my self-hosted NGINX instance when I could have just used Workers/Functions?"
  • t

    tinylobsta

    02/28/2022, 9:17 PM
    yeah, it seems like people don't know that they could easily do so many tasks with this type of pattern. it's also a lot different conceptually from how people are taught i think?
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:18 PM
    Yeah, I think the standard is more like "want a web service, use a server!"
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:18 PM
    "They even have auto-scaling servers now!"
  • t

    tinylobsta

    02/28/2022, 9:19 PM
    it seems like people either go 1) for VMs or 2) now for things like containers and kubernetes, but don't consider the intermediate benefits the programming model of a worker/function has
  • t

    tinylobsta

    02/28/2022, 9:19 PM
    maybe it's just an awareness thing like you said
  • b

    balage

    02/28/2022, 9:23 PM
    are you using @sveltejs/adapter-static?
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:24 PM
    Nope,
    @sveltejs/adapter-cloudflare
    is now available (which uses Functions for SSR)
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:24 PM
    Or
    @sveltejs/adapter-auto
    which is supposed to pick that one automatically (in practice I've found it's best to specify manually, sometimes the autopick gets it wrong)
  • d

    Deleted User

    02/28/2022, 9:25 PM
    to be fair, functions + wrangler 2 are both still betas. but yes, I do like discovering the secret sauce early
  • b

    balage

    02/28/2022, 9:26 PM
    does this mean you can fetch dynamic data using Functions and it'll be rendered into the html response on server side?
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:26 PM
    No, manually creating Functions are not compatible with the SSR adapter. What you'll need to do is use SvelteKit Endpoints, which automatically use Functions under-the-hood.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:27 PM
    (And which are dynamic)
  • b

    balage

    02/28/2022, 9:27 PM
    oh okay, is there an example app like that available on github or somehwere?
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:27 PM
    I don't know, sorry 🙂
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:27 PM
    But there's not much custom cloudflare-specific config.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:28 PM
    Just use SvelteKit endpoints like the SvelteKit docs say and it'll "just work"™️
  • b

    balage

    02/28/2022, 9:28 PM
    alright, thanks
  • l

    Larry

    02/28/2022, 9:38 PM
    True, you cannot use
    adapter-auto
    or
    adapter-cloudflare
    with Pages Functions, but I'm going to assume that @User is trying to decide between using one or the other and point him to a longer answer a few days ago: https://discord.com/channels/595317990191398933/910978223968518144/946258820416540742
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:39 PM
    The one thing I can think of that you're missing there is the Durable Object bindings; they're accessible on SvelteKit endpoints under
    platform.env
    on the input.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:40 PM
    So it would be exactly the same as inside a Function.
  • l

    Larry

    02/28/2022, 9:41 PM
    If I knew then, what I know now... 🙂
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:41 PM
    😄
  • l

    Larry

    02/28/2022, 9:45 PM
    I had actually figured that out when I was trying my alternative 1, but I was trying to use a test environment provided by someone working on the SvelteKit team that called miniflare directly. Back then, I couldn't figure out how to modify his test environment to enable durable object bindings. I've since read most of the docs on miniflare and could probably have figured it knowing what I know now.
  • i

    Isaac McFadyen | YYZ01

    02/28/2022, 9:46 PM
    Oh, yeah. I'd also follow
    wrangler2
    since it's what's integrating Miniflare for local dev.
  • l

    Larry

    02/28/2022, 9:48 PM
    Not on that channel but I have already put a pull request in against wrangler2 to enable durable object binding on call to
    wrangler pages dev
    . Here is how I now load my test environment,
    @transformation-dev/wrangler pages dev --binding DEBUG=\"blueprint:*\" --mount transformation-durable_objects=./durable_objects --do COUNTER=Counter@transformation-durable_objects --proxy 3001 -- vite preview --host"
  • l

    Larry

    02/28/2022, 9:51 PM
    I'm rather fond of my test setup now. I get to use rapid vite build cycles for the UI, I have a watch on
    ./durable_objects
    that auto rebuilds (including imports) my durable objects on source file change. I have code coverage metrics on the UI, but I still don't have it on durable objects. The Miniflare embedded in wrangler is somehow blocking that but I'll figure it out eventually.
  • b

    balage

    02/28/2022, 9:56 PM
    do I need to create a wrangler.toml file and publish it with wrangler, or can I just link my github repo to Pages?
  • l

    Larry

    02/28/2022, 9:58 PM
    Just link your repo to Pages. wrangler.toml is ignored as best I can tell.
1...858687...392Latest