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

    Piper | Cloudflare Waiting Room

    11/22/2021, 8:08 AM
    👍 Works for me!
  • w

    wonkrattle

    11/22/2021, 8:20 AM
    you can use environment variables, but they're not technically secrets because they're not encrypted
  • w

    wonkrattle

    11/22/2021, 8:21 AM
    so if you're just looking to store like an API key or something like that, that's what I'd use
  • w

    wonkrattle

    11/22/2021, 8:21 AM
    then you just reference it in your code like a variable but in ALL_CAPS
  • w

    wonkrattle

    11/22/2021, 8:34 AM
    okay maybe not, but i did read it was possible
  • w

    wonkrattle

    11/22/2021, 9:09 AM
    But yeah if somebody knows how to reference environment variables in a function, or to create secrets, I would appreciate understanding that as well
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 9:12 AM
    Just use
    .on()
    multiple times! So:
    Copy code
    js
    new HTMLRewriter().on('div', {}).on('img', {})
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 9:13 AM
    env.MY_ENV_VAR
    And you could use KV if you need to encrypt these secrets right now. But official secrets support is not far away.
  • w

    wonkrattle

    11/22/2021, 9:14 AM
    I mean, they’re not visible to anybody other than you guys right?
  • w

    wonkrattle

    11/22/2021, 9:15 AM
    And anyone with access to the configuration page
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 9:16 AM
    Environment variables are stored as plain text, and yeah, can be seen by a select few of the Cloudflare team, as well as anyone who has access to your account.
  • w

    wonkrattle

    11/22/2021, 9:16 AM
    Whereas secrets can only be seen by machines once they are stored
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 9:17 AM
    Correct
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 9:17 AM
    And I believe KV is similarly encrypted, (but you can see those values yourself if you look them up in dash)
  • w

    wonkrattle

    11/22/2021, 9:18 AM
    But yeah this is another example of my biggest request for you guys, I couldn’t find a single thing showing me an example of that and I looked pretty hard. But I’m sure to somebody who does JavaScript a lot, it’s just painfully obvious.
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 9:18 AM
    Docs are open-source, so feel free to submit a PR with improvements!
  • w

    wonkrattle

    11/22/2021, 9:19 AM
    Oh interesting, I did see the links to GitHub but I had no idea that it was something you guys actually like wanted people to do
  • w

    wonkrattle

    11/22/2021, 9:21 AM
    I mean I don’t think the docs are bad, they are just written for people who are full-time engineers. and you guys have built something that’s useful enough to the wide world, that a lot of people would benefit from having a “documentation for people who know enough to set this up but don’t do this professionally”
  • w

    wonkrattle

    11/22/2021, 9:21 AM
    So yeah, I’ll take a look at writing a version of the functions page that does that.
  • d

    dominic

    11/22/2021, 10:44 AM
    Is there a way to view function error logs in production?
  • g

    geelen

    11/22/2021, 10:56 AM
    not yet, sorry. You should wrap your code in a try/catch and send errors to Sentry or something for observability
  • w

    wonkrattle

    11/22/2021, 10:57 AM
    @User I just tried this with the result: ReferenceError: env is not defined
  • g

    Greg Brimble | Cloudflare Pages

    11/22/2021, 10:57 AM
    You’ve got to grab env from the context parameter.
  • w

    wonkrattle

    11/22/2021, 10:57 AM
    How do I do that?
  • w

    wonkrattle

    11/22/2021, 10:59 AM
    Is that just context.env,VAR
  • w

    wonkrattle

    11/22/2021, 11:01 AM
    Oh I think I might understand
  • w

    wonkrattle

    11/22/2021, 11:02 AM
    I had to add it here: const { latitude, longitude, city, country, timezone, env } = request.cf
  • w

    wonkrattle

    11/22/2021, 11:44 AM
    Oh I see what it is, it’s up above
  • k

    kavinplays

    11/22/2021, 11:53 AM
    That's why the open source nature, majority of people writing those docs are the people who made the stuff, it's often difficult to think about it in other people's shoes imo
  • d

    Deleted User

    11/22/2021, 12:06 PM
    wrong erwin :D
1...141516...392Latest