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

    geelen

    02/18/2022, 10:00 AM
    Pages doesn't read from wrangler.toml at all
  • g

    geelen

    02/18/2022, 10:03 AM
    docs here: https://developers.cloudflare.com/pages/platform/functions#durable-object-namespace
  • c

    CrownedHead

    02/18/2022, 5:26 PM
    @User thank you! I was able to get it working.
  • f

    fubhy

    02/18/2022, 5:43 PM
    Hey guys. I'm in the middle of migrating our app from Vercel to Cloudflare Pages and only now realized that there's a limit of 100.000 function calls per day. I'm not sure if we are going to hit that limit or not but we were forced to migrate from Vercel because of an issue with their service (security report pending, can't disclose more details at this time). I already submitted the form to have this limit increased but is there any way this request could get fast tracked? I hate to ask this but given the circumstances I'd really appreciate it πŸ˜‰
  • f

    fubhy

    02/18/2022, 5:43 PM
    Basically this is the last thing before I can pull the trigger and route traffic to the new setup on CF Pages.
  • f

    fubhy

    02/18/2022, 5:45 PM
    PS: We are currently on the Business plan but would also be happy to talk about Enterprise tier if that's a requirement for that.
  • g

    Greg Brimble | Cloudflare Pages

    02/18/2022, 5:46 PM
    I'll reach out to the Pages PM for you. What's your account ID?
  • f

    fubhy

    02/18/2022, 5:47 PM
    Thanks. Can I DM you the account id?
  • g

    Greg Brimble | Cloudflare Pages

    02/18/2022, 5:47 PM
    Of course!
  • c

    CrownedHead

    02/18/2022, 8:12 PM
    I have another question regarding functions: I'm setting up an AB testing function that is run an all slugs. The idea is that if that slug doesn't already exist as a page it will run the ab test to redirect to a "control" or "test" page, but if that slug exists as a page then to direct the traffic to that page. The issue I'm running into is that if a slug triggers a function AND a page exists that has that same slug than it is impossible to reach the page, you can only trigger the function. The files structure looks like this: β”œβ”€β”€ functions β”‚ β”œβ”€β”€ [path].ts | β”œβ”€β”€ Pages β”‚ β”œβ”€β”€ funnel.ts β”‚ β”œβ”€β”€ sale.ts As an example navigating to website.com/funnel will trigger the function and it is impossible to redirect from the function to the funnel page (triggers a recursive call error in the function). Is there anyway to navigate from the function to the page on the same slug? Thanks. I appreciate how helpful everyone has been
  • i

    Isaac McFadyen | YYZ01

    02/18/2022, 8:12 PM
    Yup, you have to
    return await event.next()
    where event is the input to your Function.
  • i

    Isaac McFadyen | YYZ01

    02/18/2022, 8:13 PM
    That allows the static file with the same route to be sent as a response.
  • c

    CrownedHead

    02/18/2022, 8:15 PM
    @User That's perfect! Thank you. And then is there a way to programmatically check if a page exists at that slug? Or should I call my api to gather that info.
  • i

    Isaac McFadyen | YYZ01

    02/18/2022, 8:16 PM
    I'm not sure... I think
    event.next()
    will return
    null
    if the page doesn't exist but I'd check to confirm that since I'm not sure.
  • c

    CrownedHead

    02/18/2022, 8:16 PM
    @User That's enough to go on. If not I can set something up with my CMS' api. Thanks a bunch for the quick assistance!
  • i

    Isaac McFadyen | YYZ01

    02/18/2022, 8:17 PM
    No problem! πŸ™‚
  • j

    Jason Shore

    02/18/2022, 8:31 PM
    Does anyone happen to have an example of using stripe in a Cloudflare pages functions folder? The example given https://github.com/cloudflare/stripe.pages.dev uses worktop (which I have never heard of before this repo) to build the application. If you try and use the examples for stripe workers the build fails.
  • j

    Jason Shore

    02/18/2022, 8:35 PM
    Error message when using stripe in the functions folder
    Copy code
    21:41:02.798    5 error(s) and 0 warning(s) when compiling Worker.
    21:41:02.800    Build failed with 5 errors:
    21:41:02.800    ../../../buildhome/repo/node_modules/stripe/lib/StripeResource.js:3:21: ERROR: Could not resolve "path"
    21:41:02.800    ../../../buildhome/repo/node_modules/stripe/lib/crypto/NodeCryptoProvider.js:3:23: ERROR: Could not resolve "crypto"
    21:41:02.800    ../../../buildhome/repo/node_modules/stripe/lib/net/NodeHttpClient.js:3:21: ERROR: Could not resolve "http"
    21:41:02.800    ../../../buildhome/repo/node_modules/stripe/lib/net/NodeHttpClient.js:4:22: ERROR: Could not resolve "https"
    21:41:02.800    ../../../buildhome/repo/node_modules/stripe/lib/utils.js:5:23: ERROR: Could not resolve "crypto"
    21:41:02.811    Failed building Pages Functions from /functions.
  • l

    Larry

    02/18/2022, 9:02 PM
    Can anyone give me an example syntax of binding a durable object when using
    wrangler pages dev --do COUNTER=Counter
    . I get ERR_CLASS_NOT_FOUND no matter what I try. @User, this is essentially the same question as a week ago, but I've tried a lot more since then, and I can now confirm that it works in prod.
  • z

    zeshhaan

    02/19/2022, 5:32 AM
    Hi, totally new to all these cloud/be/db things! Can i create an api endpoint for my pages site using functions? For example, can i have a
    .json
    endpoint to fetch data and generate UI for my site?
  • e

    Erwin

    02/19/2022, 8:15 AM
    Yup.. that is exactly what they are made for. To do those sorts of things.
  • b

    Brock

    02/19/2022, 8:16 PM
    Is it possible to import stripe in functions? I keep getting the error:
    Copy code
    13:10:50.415    ✘ [ERROR] Could not resolve "stripe"
    13:10:50.415    
    13:10:50.415        ../../../buildhome/repo/functions/activation.js:2:27:
    13:10:50.415          2 β”‚     const Stripe = require("stripe");
    13:10:50.415            β•΅                            ~~~~~~~~
    13:10:50.415    
    13:10:50.415      You can mark the path "stripe" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.
  • k

    Kieran Huggins

    02/20/2022, 8:05 AM
    Is there any way to read from the filesystem in a function? I'd like to return the contents of one of many pre-rendered JSON files based on the req country/region
  • j

    JustinNoel

    02/20/2022, 1:17 PM
    Maybe see this: https://discord.com/channels/595317990191398933/779390076219686943/942137656769404978
  • r

    RaifY

    02/20/2022, 4:01 PM
    Why upload files are not be treated as
    File
    object?
  • r

    RaifY

    02/20/2022, 4:02 PM
    According to compatibility-dates settings, it become default at
    2021-11-03
  • i

    Isaac McFadyen | YYZ01

    02/20/2022, 4:23 PM
    Make sure you're setting your compatibility date. Also, how are you determining they are not File objects?
  • r

    RaifY

    02/20/2022, 4:25 PM
    by
    something instanceof File
    , How to set compatibility date?
    wrangler.toml
    does not seems work locally
  • r

    RaifY

    02/20/2022, 4:26 PM
    Sorry I'm very new to Pages Function
  • i

    Isaac McFadyen | YYZ01

    02/20/2022, 4:31 PM
    Pages Functions don't yet use
    wrangler.toml
    . I'm not sure how to set the compatibility date actually, or even if it's available.
1...787980...392Latest