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

    ethxn

    12/12/2021, 10:45 PM
    Ah, okay. Excited to see what's to come.
  • e

    Erwin

    12/12/2021, 10:50 PM
    Oh yeah, it absolutely is.
  • e

    ethxn

    12/12/2021, 10:51 PM
    Well thanks for the info. Hopefully the proxy dosn't take long because it would be a great addition to my toolchain.
  • e

    Erwin

    12/12/2021, 11:03 PM
    I don’t know what the team’s plans are for Christmas, but I am pretty confident we will see a new round of fixes drop before before then.
  • c

    Cоlе

    12/12/2021, 11:04 PM
    Copy code
    typescript
    // Connect to MongoDB realm
    async function connect(env: any): Promise<globalThis.Realm.Services.MongoDB | Error> {
        try {
            console.log(env.REALM_APPID);
            App = App || new Realm.App(env.REALM_APPID);
            const credentials = Realm.Credentials.apiKey(env.env.REALM_AUTH_API_KEY);
            const user = await App.logIn(credentials);
            return user.mongoClient('mongodb-atlas');
        } catch (err) {
            console.log(err);
            throw err as Error;
        }
    }
    Here I'm just binding REALM_APPID from the command line
  • c

    Cоlе

    12/12/2021, 11:04 PM
    I just had to switch it from env.REALM_APPID to env.env.REALM_APPID
  • c

    Cоlе

    12/12/2021, 11:04 PM
    I'll post more when home
  • e

    Erwin

    12/12/2021, 11:18 PM
    Yeah, Pages Functions only has 1 argument called context, which has an ‘env’ property.
  • e

    Erwin

    12/12/2021, 11:19 PM
    If you see the examples, they deconstruct with {} around the env.
  • c

    Cоlе

    12/13/2021, 1:15 AM
    If I destructure it, it works on wrangler, but on staging:
    TypeError: Cannot read properties of undefined (reading 'REALM_APPID').
  • c

    Cоlе

    12/13/2021, 1:15 AM
    it was working fine until last night 😭
  • c

    Cоlе

    12/13/2021, 1:18 AM
    there isn't a log tab for pages, eh?
  • c

    Cоlе

    12/13/2021, 1:25 AM
    looks like
    env
    , destructured or not destructured, is undefined on staging 💀
  • e

    Erwin

    12/13/2021, 1:33 AM
    You need to define your settings for every environment in the Pages Dashboard..
  • c

    Cоlе

    12/13/2021, 1:48 AM
    should be good
  • c

    Cоlе

    12/13/2021, 1:48 AM
    also, I mean env is completely undefined, no "ASSETS" or anything
  • c

    Cоlе

    12/13/2021, 1:50 AM
    let me double check that actually, I might've messed up
  • c

    Cоlе

    12/13/2021, 1:51 AM
    yea I json stringify env, returns undefined
  • c

    Cоlе

    12/13/2021, 1:52 AM
    just to clarify, both
    env
    and
    { env }
  • e

    Erwin

    12/13/2021, 1:53 AM
    Can you DM me the whole thing? Including the
    onRequest*()
    call?
  • c

    Cоlе

    12/13/2021, 1:56 AM
    1m
  • n

    naansequitur

    12/13/2021, 3:53 AM
    Using wrangler locally would it pick up env vars defined in
    wrangler.toml
    ? I'm able to see the ASSETS property but nothing else
  • e

    Erwin

    12/13/2021, 3:55 AM
    No, you have to manually specify those with wrangler.. -kv or something to the
    pages dev
    command
  • n

    naansequitur

    12/13/2021, 4:01 AM
    Thanks good to know. Is there any way to see logs from deployed function executions at the moment or not yet?
  • e

    Erwin

    12/13/2021, 4:01 AM
    Not yet unfortunately
  • b

    brainm

    12/13/2021, 9:48 AM
    are there any way to cache 'cloudflare pages function' response to save resources?
  • a

    albert

    12/13/2021, 10:31 AM
    You can achieve that by using a custom domain and, optionally, creating a Page Rule with
    Cache Everything
    .
  • e

    Erwin

    12/13/2021, 11:20 AM
    Worker run before the cache, so I am pretty sure that won't actually prevent the worker from being run..
  • a

    albert

    12/13/2021, 11:23 AM
    Regular Workers do, yeah, but Pages aren't served from your zone - afaik it is more like a SSL for SaaS setup. Whether this feature is intentional or not, I'm managing to cache responses from Functions: https://pagestest.asp.gg/time
  • e

    Erwin

    12/13/2021, 11:51 AM
    Ahhh.. yeah indeed. You are correct. It is indeed SSL for SaaS under the hood..
1...414243...392Latest