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

    krsr

    02/10/2023, 5:43 AM
    just used the MailChannels pages plugin for a simple signup form on my site and it worked flawlessly on the first try. I'm blown away
  • s

    stavros-k

    02/10/2023, 8:09 AM
    Quick question, with the MailChannels pages plugin (or any other plugin). Does it have CORS setup in place? Like if a request comes to that plugin from someone (not the page itself), will the request proceed? (I'm looking to make sure that it only works from the contact form and not from curl or postman for example)
  • h

    HardAtWork

    02/10/2023, 8:18 AM
    It does not. Note too though that CORS is implemented client-side, not server side. As in, you can pass CORS headers to a client, but they can just choose to ignore them.
  • s

    stavros-k

    02/10/2023, 8:20 AM
    Hmm, right. Any ideas how to secure the endpoint? Either on the plugin or in a worker standalone.
  • h

    HardAtWork

    02/10/2023, 8:22 AM
    Only send an email when some other verification is sent? But also, the plugin serves more as an example, and you should probably write your own instead.
  • s

    stavros-k

    02/10/2023, 8:25 AM
    I already have a worker that I use for the bellow. I have a contact form, client puts his mail, form submits to my email, and also sends a copy to the mail the client put. The problem here is, anyone can start sending requests to the workers endpoint, and putting anyone's email, and writing whatever he wants in the form. Which can "impersonate" my mail. Tho the same can be done from the form, but I can have some time delay there I guess.
  • f

    frankichiro

    02/10/2023, 8:32 AM
    Hello! I am trying to publish a Pages project from Github, that uses a library called "@xata.io/client". It works locally, but when I publish to Cloudflare the deployment fails with the error "Could not resolve @xata.io/client". Does that mean I can't use it, or am I missing something?
  • f

    frankichiro

    02/10/2023, 8:53 AM
    Nevermind, I think I figured it out. I added "npm run build" as a build command in the Pages settings, and then "build: npm install @xata.io/client" as a script in package.js. It seems to have worked.
  • j

    jcovert

    02/10/2023, 4:44 PM
    Quick ? - can my Pages project have a function that's run as a cron trigger? I've added the [triggers] section in my wrangler.toml, and I can see a cron log every time it fires - but I can't seem to figure out how I'm supposed to specify my event handler. I have an index.ts inside a functions/api/scheduler/ folder (with both an addEventListener and export default, which call my handler) - but this never seems to get run. If i instead run with
    wrangler dev <path to index.ts> --test-scheduled
    , it runs - though then of course my pages aren't hosted (as it's not a pages run). Or if my question should be asked elsewhere, that would be helpful to know too
  • d

    DaveMurphySF

    02/10/2023, 5:03 PM
    I am trying to use a function to write a file R2, and I can't get any blob-type to work. Here's a very basic repro:
    Copy code
    js
    const obj = { hello: 'world' };
    const blob = new Blob([JSON.stringify(obj, null, 2)], {
            type: 'application/json',
        });
    const r2Obj = await ctx.env.PUBLIC_BUCKET.put(uuid(), blob);  // This throws an empty exception
    
    console.log(JSON.stringify(r2Obj, null, 4));
  • k

    kian

    02/10/2023, 5:05 PM
    try blob.stream() as the second argument to put
  • d

    DaveMurphySF

    02/10/2023, 5:17 PM
    Nice! That works, thanks @kian
  • j

    jgarr

    02/11/2023, 7:32 AM
    Are pages functions different from workers? I'm trying to figure out how to write to a kv namespace from a function but everything I'm finding is for workers/wrangler and I'm curious if I have to switch to that to be able to use kv
  • j

    jgarr

    02/11/2023, 7:38 AM
    nvm, I just found where the bindings settings are. They didn't show up in the page settings until I deployed a function.
  • w

    Walshy | Pages

    02/11/2023, 1:13 PM
    They're the same thing just different syntax
  • j

    jgarr

    02/11/2023, 9:42 PM
    It’s very confusing when googling and looking for examples. Do you know of an example of writing to kv from a page function? I failed to find one and do it last night
  • h

    HardAtWork

    02/11/2023, 9:44 PM
    Copy code
    js
    ctx.env.KV.put(“key”, “value”);
  • j

    jgarr

    02/11/2023, 9:45 PM
    Do I import ctx? Maybe that’s what I was missing
  • h

    HardAtWork

    02/11/2023, 9:45 PM
    No,
    ctx
    is present within the Function handler.
  • h

    HardAtWork

    02/11/2023, 9:46 PM
    Like
    Copy code
    js
    export async function onRequest(ctx) {
      await ctx.env.KV.put(“key”, “value”);
      // Do something else
    }
  • j

    jgarr

    02/11/2023, 9:56 PM
    oh cool, that wrote something. thanks!
  • d

    Deem

    02/13/2023, 6:28 PM
    Can I deploy nextjs site with prisma without prisma data proxy to pages function
  • i

    izznatsir

    02/13/2023, 10:22 PM
    Currently pages functions has the same pricing and request limit as workers, how does the size limit of workers applies to pages functions? Does every pages function file count as one worker or does cloudflare bundle all pages function files into one worker?
  • i

    izznatsir

    02/13/2023, 10:23 PM
    Sorry if it has been asked before, but using Discord search bar and the official docs didn't bring any result
  • k

    kian

    02/13/2023, 10:25 PM
    Yes, the limits are the same
  • k

    kian

    02/13/2023, 10:25 PM
    All of your Functions files are bundled into 1 Worker
  • i

    izznatsir

    02/13/2023, 10:29 PM
    Thanks for the quick answer! Is there any plan to map each function file to separate worker?
  • i

    izznatsir

    02/13/2023, 10:31 PM
    Just like Vercel edge functions.
  • i

    izznatsir

    02/13/2023, 10:34 PM
    I think this information should be included in the docs.
  • h

    HardAtWork

    02/13/2023, 10:36 PM
    AFAIK, Edge Functions are also a single deployed Worker
1...343344345...392Latest