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

    Lostballoon

    02/26/2022, 1:48 AM
    found it 😅
    --binding ENV_NAME=\"ENV_VALUE\"
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 1:48 AM
    Yup. If you want to load from an .env file you can also do
    --binding $(cat .env)
    (make sure your .env has no spaces or quotes).
  • l

    Lostballoon

    02/26/2022, 1:50 AM
    ohhh that sound great, can a .env file be comitted to version control, obviously omitting the secret keys, or not recommended i guess
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 1:50 AM
    Yeah, an
    .env
    file could be committed to Version Control. I wouldn't recommend it considering it's very common for people to put secrets in there cause they assume it's not committed, but it's possible if you're careful.
  • l

    Lostballoon

    02/26/2022, 1:51 AM
    cool, thanks a lot! 🙂
  • r

    RaifY

    02/26/2022, 9:07 AM
    I'm here again🤣 . It looks like
    @ssttevee/cfw-formdata-polyfill
    can only handle uploads from requests, so if I want to build a new form containing a file, what should I do?
  • j

    JustinNoel

    02/26/2022, 9:22 AM
    I'm assuming you want the
    .env
    file there for another dev to be able to know what variables to use and then fill it out. I'd recommend a file named
    .env.template
    . That way, it's clear this is the
    .env
    file without the actual values. I'd be very worried someone along the way would mistakenly commit the real
    .env
    file changes with the secrets in it.
  • r

    RaifY

    02/26/2022, 10:41 AM
    Use some patches to make it just work
  • l

    Lostballoon

    02/26/2022, 2:31 PM
    stupid question, but how do you handle in your .env file values containing spaces? 😅
  • k

    kian

    02/26/2022, 2:38 PM
    Can’t you just enclose the value in quotes?
  • l

    Lostballoon

    02/26/2022, 3:03 PM
    nope, it adds the quotes to my value, I even tried escaping it with
    \"
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 3:07 PM
    Yeah, that's one of the issues with the
    --binding
    hack. I couldn't figure out how to make it work, actually.
  • k

    Kai

    02/26/2022, 5:51 PM
    when building a new product, is pages + functions preferable over pages + workers?
  • g

    Greg Brimble | Cloudflare Pages

    02/26/2022, 6:06 PM
    Generally, yes.
  • g

    Greg Brimble | Cloudflare Pages

    02/26/2022, 6:07 PM
    But Functions is still in beta right now, so if you need something production-ready, you might prefer Workers until we've got everything worked out for GA.
  • k

    Kai

    02/26/2022, 6:09 PM
    I don't mind the beta status, but thinking how this would work from an architectural pov. From what I understand all functions + the page need to be defined in one place, but for a large solution that wants to have both an API and a largely decoupled web UI this isn't really that nice
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 6:10 PM
    Yeah, Functions have to be pushed with your UI, so it's coupled tightly. Although you could still do pushes where you only update the Functions, not the UI.
  • k

    Kai

    02/26/2022, 6:10 PM
    right, it also means anyone working on the API needs to pull the UI as well, and vice versa, not sure that makes sense 🤔
  • k

    Kai

    02/26/2022, 6:11 PM
    Is there actually a sample solution somewhere that would demonstrate how this can work in anything larger then a simple todo list?
  • k

    Kai

    02/26/2022, 6:11 PM
    (or does someone have some experience to share?)
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 6:12 PM
    I have experience with Functions. So the main way this would work is that you have a Function for each route, like:
    /shop.ts
    /shop/[slug].ts
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 6:12 PM
    Functions can either act as their own routes or intercept normal requests.
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 6:13 PM
    When they intercept normal requests, you can modify the static content however you want, as well as the request and response.
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 6:14 PM
    I think there's actually a repo somewhere though with an example? Sec. Can't find it 😆
  • g

    Greg Brimble | Cloudflare Pages

    02/26/2022, 6:14 PM
    You're correct. The main premise of Functions is to let you deploy a full-stack app from a single-source of truth, API and UI together. If you want to decouple it because you have multiple clients other than just your UI, Functions might not be the best fit. But you'll sacrifice the nice things that coupling does give you (easy rollbacks, previews, etc.).
  • k

    Kai

    02/26/2022, 6:16 PM
    makes sense, though I think workers makes more sense in general for me then, since I plan to make most of the API use GraphQL (so not many endpoints), and have other clients next to the web UI, so I think most of the extra benefits from functions isn't really worth it
  • g

    Greg Brimble | Cloudflare Pages

    02/26/2022, 6:17 PM
    You definitely can still have a GraphQL API in Functions, but yeah, do whatever's best for your workflow. Should be pretty easy to switch between the two if you ever change your mind.
  • i

    Isaac McFadyen | YYZ01

    02/26/2022, 6:17 PM
    Also, AFAIK Functions don't support a custom bundler yet, so there's that too.
  • k

    Kai

    02/26/2022, 6:20 PM
    👍 thanks a lot for the explanation
  • h

    HardAtWork

    02/26/2022, 6:20 PM
    Unless you use
    _worker.js
    .
1...828384...392Latest