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

    Erwin

    12/15/2021, 8:08 AM
    I would assume they are the same as Bundled
  • m

    markdessain

    12/15/2021, 10:32 AM
    If our Cloudflare pages site has functions enabled. Do the hits to the static resources such as html, css, is count towards the function limit (100,000 per day)
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 10:50 AM
    You need to grab it from the context parameter.
    Copy code
    ts
    export const onRequest = async (context) => {
      return new Response(context.env.NEXT_PUBLIC_NHOST_GRAPHQL_API)
    }
    https://developers.cloudflare.com/pages/platform/functions#environment-variable
  • s

    Subh

    12/15/2021, 10:55 AM
    Aha, this makes sense
  • e

    Erwin

    12/15/2021, 10:59 AM
    Currently yes
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 2:04 PM
    We've just shipped a new
    wrangler@alpha
    if anyone's feeling adventurous and wants to try out our new static assets server. TL;DR: - much more faithful simulation of how Pages actually serves assets in production, including SPA routing,
    _headers
    and
    _redirects
    support - better error handling in your scripts (hopefully no more crashing the entire server!) Let us know how you get on 🙂
  • s

    stonys

    12/15/2021, 2:09 PM
    Hi, are there any updates about TypeError:
    Cannot reconstruct a Request with a used body
    , when the POST body is not empty? Thanks
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 3:34 PM
    Should be fixed in local dev, but unfortunately still not quite yet in production. We're working on it!
  • p

    PatrickJ

    12/15/2021, 3:51 PM
    Is there still a 1 MB limit in Pages Functions?
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 3:53 PM
    Yes. If you're needing a higher limit, I think you're best to fill this form out: https://www.cloudflare.com/en-gb/larger-scripts-on-workers-early-access/
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 3:53 PM
    Pages should inherit your account's limit.
  • p

    PatrickJ

    12/15/2021, 4:05 PM
    Thanks Greg. To add some more context: we are looking into deploying https://vite-plugin-ssr.com/ on the CF Pages. In regular server environments, it works in a way, where vite-plugin-ssr provides tiny express middleware which grabs generated app files from dist folder and responds with SSR site. For serverless environments they suggest bundling the whole thing to the single file, and before Pages Functions, that was the way to go with Cloudflare. Is that serverless approach still a way to go, or it is now possible to do it without bundling, similar to regular server approach?
  • j

    JustinNoel

    12/15/2021, 4:28 PM
    Does this change include handling locally persistent KV data?
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 4:49 PM
    We introduced persisted KV, DO & cache a couple of releases ago! 🙂 Can't remember if that's in the beta yet, but certainly it's available in alpha.
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 4:51 PM
    If your pages are heavy, I think some prerendering makes sense still. I'm not familiar with Vite myself, so can't comment on that specific plugin, but I'd probably just recommend trying it out both ways and seeing how they perform
  • d

    Deleted User

    12/15/2021, 7:08 PM
    Hello, I'm would like to use this workers example script inside of my Cloudflare Pages deployment, but I'm stuck on how I would be able to use this with it. Also, is there anyway of making an entire directory ONLY being protected using that script, as I'd like a specific directory eg. /private/* to be protected with HTTP Basic authentication, thanks!
  • p

    pxkq

    12/15/2021, 7:40 PM
    I haven't looked too deeply on that
    basic-auth
    , but take a look at _middleware: https://developers.cloudflare.com/pages/platform/functions#adding-middleware You should be able to create a private directory with the auth middleware inside and only the functions of that directory or deeper will have it
  • d

    Deleted User

    12/15/2021, 8:27 PM
    Thanks! I'll check it out
  • p

    pxkq

    12/16/2021, 6:18 PM
    How would I measure or see the CPU consumption of a function?
  • h

    HardAtWork

    12/16/2021, 6:19 PM
    Metrics like that are not exposed to the user/programmer for the most part, for security reasons.
  • p

    pxkq

    12/16/2021, 6:19 PM
    How do you know if your function will be rejected due to cpu time?
  • h

    HardAtWork

    12/16/2021, 6:21 PM
    You can use something like Miniflare, and measure the execution time with DevTools that way. It isn't exactly one-to-one, but it is about the closest you will get.
  • p

    pxkq

    12/16/2021, 6:23 PM
    Alright, although it won't account for cpu difference or worst, i/o 😦
  • h

    HardAtWork

    12/16/2021, 6:26 PM
    TBH, Miniflare is usually pretty accurate. I have tested a program on Miniflare on 3 separate cloud instance, a Dell Laptop and a pretty powerful desktop, and as long as it can execute a decent sized Node program without struggling, you should get similar results to deploying it to Workers itself.
  • h

    HardAtWork

    12/16/2021, 6:27 PM
    And if you are worried about I/O, run it on a Cloud Instance, so that your ISP can't be a bottleneck.
  • p

    pxkq

    12/16/2021, 6:35 PM
    It's more like the network between the worker and a 3rd party. The whole thing takes 1225ms on my example, but obviously that's mostly io, not cpu consumption. Anyway thanks 🙏
  • e

    Erwin

    12/16/2021, 11:48 PM
    Unless you are doing something extremely CPU intensive, it is very hard to break the 50ms CPU limit. I think our average worker execution time is like 4ms.
  • p

    pxkq

    12/17/2021, 12:05 AM
    It's not really an intensive task, but it queries a 3rd party with a paginated resource, with potentially any number of pages. But I'm gonna just set a limit and call it multiple times if need be.
  • e

    Erwin

    12/17/2021, 2:44 AM
    Sounds like a very decent solution
  • c

    Cоlе

    12/17/2021, 8:50 AM
    Came back from my exam week off, it looks like it resolved itself. Also, you were completely right about the destructuring; someone pushed a bad commit earlier, and I didn't notice 😮‍💨
1...444546...392Latest