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

    geelen

    01/26/2022, 4:26 PM
    so if you have a ton of stuff installed but never import it, it won't get bundled up
  • m

    marahmanjs

    01/26/2022, 6:30 PM
    I have a function that uses node package but during build it fails with error The package "stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error
  • w

    Wallacy

    01/26/2022, 11:50 PM
    Just to make sure.... After que GA of Pages Functions, using the module workers (_workers.js) when we failback to pages assets (env.ASSETS.fetch(request) ) that will not count as functions call right?
  • w

    Wallacy

    01/26/2022, 11:52 PM
    Or will be equal to Worker Sites? (Every page will be one request anyway);
  • z

    zsmooth

    01/27/2022, 12:10 AM
    That means you’re trying to use a package that is targeted at node, and it won’t work in a worker
  • e

    Epailes

    01/27/2022, 10:20 AM
    I believe if pages handles the serving of the static asset, it won't count as a function call. If you have some sort of code that runs and falls back to serving the asset manually, that would count as a function call.
  • e

    Epailes

    01/27/2022, 10:22 AM
    As functions are built on top of workers, does that mean we can use the same image optimizations mentioned in the docs without it being a worker? https://developers.cloudflare.com/images/image-resizing/control-origin-access Additionally, as cf pages are effectively the "origin", does that mean we can add the cloudflare cache headers to the response, and future images would be served via the cloudflare cdn instead of invoking the function? (Whereas doing this in a worker requires an invocation for every load of an image, as workers always run on matching url patterns)
  • s

    steranevdy

    01/27/2022, 11:33 AM
    is there an example how do you configure local durable objects with the "--do" option?
  • c

    Cоlе

    01/30/2022, 2:00 AM
    I'm back to cause more trouble
  • c

    Cоlе

    01/30/2022, 2:02 AM
    I'm running this script to intercept certain requests, and have them serve my index page (for angular routing)
    Copy code
    ts
    import { Regexes } from '@vl-types/regexes';
    
    export const onRequestGet: PagesFunction<{}> = async ({ request, env, next, data, params }) => {
        if (Regexes.username.test(params.id as string)) {
            // Redirect to main page
            const cloned = request.clone();
            const dest = `${(env as any).BASE_URL}`;
            return env.ASSETS.fetch(new Request(dest, { headers: cloned.headers }));
        }
    
        return next();
    };
    On wrangler, it works fine. On pages, it throws 406
  • c

    Cоlе

    01/30/2022, 2:03 AM
    I saw from the cf troubleshooting pages to watch out for
    Accept-*
    headers, so I made sure to throw in the headers from the original request
  • b

    bsam75

    01/31/2022, 3:29 PM
    If I have a function like /functions/[[slug]].js. This function returns a static asset if it exists, but if not it pulls from a KV store. Will it count against my 100k daily limit on each run, or only if the static asset does not exist?
  • j

    James

    01/31/2022, 3:38 PM
    Currently it does count, but I know the team want to resolve this so that requests that only serve a static asset do not count towards the limit, before GA.
  • b

    bsam75

    01/31/2022, 3:39 PM
    Thanks alot, im going to try it and if we get close to hitting the cap i'll request more
  • z

    zsmooth

    01/31/2022, 8:13 PM
    I put in a request to raise my limit a week ago and still haven’t heard anything. Hopefully you have better luck. 😀 (i don’t actually need to raise it any more, I moved to Workers)
  • p

    pencilflip

    01/31/2022, 11:40 PM
    hey all, I'm looking to use Cloudflare Functions to add dynamic meta tags to my CRA website. E.g. I want to make it so that when you go to
    /foo
    , then the header tags look like
    <meta name="description" content="foo"/>
    , and when you go to
    /bar
    , the header tags look like
    <meta name="description" content="bar"/>
  • p

    pencilflip

    01/31/2022, 11:41 PM
    so basically, I just want to render my CRA website normally, but change some tags in the HTML
  • p

    pencilflip

    01/31/2022, 11:41 PM
    not quite sure how to go about doing this though...
  • z

    zsmooth

    01/31/2022, 11:56 PM
    Since it’s CRA, those navigations would be client side right? Or do you mean on the first load, you want them set correctly?
  • z

    zsmooth

    01/31/2022, 11:59 PM
    Is your CRA app on Pages already?
  • p

    pencilflip

    02/01/2022, 12:16 AM
    yea
  • p

    pencilflip

    02/01/2022, 12:16 AM
    i just want this for link previews
  • p

    pencilflip

    02/01/2022, 12:16 AM
    e.g. when you share a link on Twitter/FB/etc
  • z

    zsmooth

    02/01/2022, 12:16 AM
    Gotcha. I believe you can put a worker in front if you’re using a custom domain
  • z

    zsmooth

    02/01/2022, 12:17 AM
    And it would fetch from the origin and use HTMLRewriter. I’ve never done it but from what I’ve read it should be straightforward
  • p

    pencilflip

    02/01/2022, 12:18 AM
    hm, do you know of any resources that walk through this
  • z

    zsmooth

    02/01/2022, 12:19 AM
    Oh but you asked about functions… with a function, you would fetch the static asset (built html) from the ASSETS KV, but everything else would be the same
  • p

    pencilflip

    02/01/2022, 12:22 AM
    so if my HTML file is in
    build/index.html
    and my functions code is in
    functions/foo.ts
    , how would I return the static html?
  • z

    zsmooth

    02/01/2022, 12:25 AM
    I’m on my phone right now, I’ll try to show you some more code when I’m back at a computer. But you’ll basically ask the worker for the asset for that request, and if it gives you back html, you can update it. Using HTMLRewriter you can update it efficiently but since it’s a CRA the html is mostly a shim and you could probably just modify it as a string
  • p

    pencilflip

    02/01/2022, 12:26 AM
    gotcha thanks for the help
1...697071...392Latest