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

    Cоlе

    01/15/2022, 10:20 PM
    If you're looking to do anything that big, Rust might be that way to go (even just for performance sake, you might hit the execution time ceiling quickly with JS)
  • c

    Cоlе

    01/15/2022, 10:21 PM
    The example takes about 20ms, and the project I'm using it with (the minecraft inventory, opacity blending, color blending, etc), takes about ~30-40ms
  • c

    Cоlе

    01/15/2022, 10:21 PM
    not a ton of headroom
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2022, 10:21 PM
    Yeah, I'm looking to add generated social images to my site soon. Probably going to go with rust, but if you had just happened to stumble across an easy JS one, I might have gone that route. Thanks for sharing the write up—it's really very very cool
  • c

    Cоlе

    01/15/2022, 10:21 PM
    I'll definitely keep my eyes open. Thanks!
  • i

    itsmatteomanf

    01/15/2022, 11:29 PM
    That'd interesting to see! I'm very tempted myself... 500+ pages of social images and text doesn't sound fun doing by hand ahah
  • m

    mike.pete

    01/16/2022, 3:03 AM
    Good evening 🙂 Are functions mapped to workers? I want to deploy an Apollo GQL server using functions, but I'm not sure how to go about this. https://github.com/cloudflare/workers-graphql-server
  • g

    Gary Somerhalder

    01/16/2022, 3:37 AM
    @mike.pete I don’t know about functions. You can deploy this on workers. I’ve done it. We have a lot of Apollo experience.
  • h

    HardAtWork

    01/16/2022, 3:37 AM
    Replies should ping automatically.
  • m

    mike.pete

    01/16/2022, 3:38 AM
    Thanks Gary 🙂
  • h

    HardAtWork

    01/16/2022, 3:38 AM
    Functions aren’t a 1-to-1, but you can probably deploy it in advanced mode with a _worker.js file
  • g

    Gary Somerhalder

    01/16/2022, 3:38 AM
    Are you doing a monolith Apollo GraphQL Server?
  • m

    mike.pete

    01/16/2022, 3:39 AM
    That sounds promising, are there docs on this anywhere?
  • m

    mike.pete

    01/16/2022, 3:41 AM
    I was hoping to keep everything in Pages (mostly for ease of deployment) but I'm still pretty new to Cloudflare and GQL in general.
  • h

    HardAtWork

    01/16/2022, 3:41 AM
    https://developers.cloudflare.com/pages/platform/functions#advanced-mode for how to deploy _workers.js files, but no specific tutorial for GraphQL.
  • m

    mike.pete

    01/16/2022, 3:42 AM
    Also tbh, I'm not entirely sure what you mean by
    Copy code
    monolith Apollo GraphQL Server
  • m

    mike.pete

    01/16/2022, 3:43 AM
    Awesome, I'll check it out! Thank you!
  • h

    HardAtWork

    01/16/2022, 3:43 AM
    No problem, happy to help!
  • c

    Cоlе

    01/16/2022, 6:18 AM
    would someone be willing to try the https://blog.cloudflare.com/introducing-the-workers-cache-api-giving-you-control-over-how-your-content-is-cached/ example on pages?
  • c

    Cоlе

    01/16/2022, 6:19 AM
    thanks to Greg, I was able to get my stuff to compile, but I'm getting "undefined" from
    cache.match()
    on local, and 1101 errors on prod
  • c

    Cоlе

    01/16/2022, 6:19 AM
    I'm gonna try to dig and get more info when I can, but this feels wack
  • g

    Greg Brimble | Cloudflare Pages

    01/16/2022, 11:26 AM
    Can you post your latest version of the code?
  • g

    Greg Brimble | Cloudflare Pages

    01/16/2022, 11:28 AM
    Definitely should be possible! Either with a file in your
    functions
    directory, or with the
    _worker.js
    as mentioned below. I’d personally only go with
    _worker.js
    if you’ve got a custom build process that you need.
  • m

    mike.pete

    01/16/2022, 4:07 PM
    That's good to know, thanks Greg!
  • c

    Cоlе

    01/16/2022, 5:43 PM
    Right now I'm just using the boilerplate from the blog post, minus this bit:
    Copy code
    js
    let hash = await sha256(body)
    
    let url = new URL(request.url)
    url.pathname = "/posts" + url.pathname + hash
    Is the hashing part required?
  • c

    Cоlе

    01/16/2022, 5:43 PM
    I'll post more when I'm back from work
  • c

    Cоlе

    01/17/2022, 1:15 AM
    sorry for the goose chase, I appreciate the help 🙏
  • c

    Cоlе

    01/17/2022, 1:15 AM
    this is my exact GET function:
    Copy code
    ts
    export const onRequestGet: PagesFunction<{}> = async ({ request, env }): Promise<Response> => {
        const doc = "getKits";
        const subject = "MJ00Y";
        cache = cache || await caches.open('kits');
    
        const cacheKey = new Request(request.url, {
            headers: request.headers,
            method: 'GET'
        });
    
        const cached = await cache.match(request);
    
        if (cached) {
            const cloned = cached.clone();
            cloned.headers.set('cf-cache-status', 'HIT');
            return cloned;
        }
    
        let real = GetMongoDocument(env, collectionName, { _id: query(subject!) }).then(async (res) => {
            const response = toJSON(res);
            cache.put(cacheKey, response.clone());
            response.headers.set('cf-cache-status', 'MISS');
            return response;
        }).catch((err) => {
            return toError(Errors.ERR_INTERNAL_ERROR, doc, err);
        });
    
        return real;
    };
  • c

    Cоlе

    01/17/2022, 1:17 AM
    I fixed the 1000 error (whoops). I'm getting "MISS" on each request
  • j

    James

    01/17/2022, 1:22 AM
    You probably need to
    waitUntil
    the
    cache.put
    to ensure it actually runs, since it returns a promise. It’s available like request and env with functions.
1...626364...392Latest