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

    Cоlе

    01/14/2022, 4:11 AM
    I've checked and sure enough, cache is returning undefined 100% of the time, all that changes is the
    await cache.put
    . Here's what I get when I comment out the
    await cache.put
    (same with result/without await, but good catch)
  • c

    Cоlе

    01/14/2022, 4:18 AM
    it's weird, it's almost like the
    cache.put
    is returning the function on its own
  • c

    Cоlе

    01/14/2022, 8:09 AM
    not quite, all of it is done within a single workers (pages function). I've doing lots of database requests and asset requests, which seem to take a decent amount of time
  • c

    Cоlе

    01/14/2022, 8:09 AM
    but the actual rendering does not take much at all, or at least it seems to work fine?
  • c

    Cоlе

    01/14/2022, 8:10 AM
    I've done more work on the renderer, check this out: https://kits.aoelite.me/?KGSV2
  • c

    Cоlе

    01/14/2022, 8:11 AM
    still needs some work, but now I've doubled the image size, extra rendering layers for item-counts, potion overlays, and enchantments
  • c

    Cоlе

    01/14/2022, 8:12 AM
    timing wise, it actually takes surprisingly little amount of time to put together, despite how inefficient it is
  • c

    Cоlе

    01/14/2022, 8:13 AM
    cold start usually around 50ms~ without db/assets. after hitting ctrl+r a few times, it's down to <10ms
  • c

    Cоlе

    01/14/2022, 8:13 AM
    idk how that'll affect my bill tho 💀
  • c

    Cоlе

    01/14/2022, 8:14 AM
    it'd also be easier if I could use something like
    dom-to-image
    except that it doesn't support ES6 modules, so I basically had to rewrite the same program in 2 different formats
  • c

    Cоlе

    01/14/2022, 8:15 AM
    or canvas 🙄
  • c

    Cоlе

    01/14/2022, 8:20 AM
    In all honesty tho, it's not bad at all. Once I got all images to the same proportion, it's ultra straightforward. I implemented a basic colour blending algorithm with no problems at all. There's a small gap to overcoming overflowing colour values, but it's no big deal
  • c

    Cоlе

    01/14/2022, 8:22 AM
    If I get time, I honestly wouldn't mind doing a proper write/tutorial on it, it's just that A. company code means I gotta do it from scratch, and B. it probably shouldn't be this hard 😢
  • c

    Cоlе

    01/14/2022, 8:32 AM
    *it's also worth mentioning that you can serve it as a png, and provide your own caching headers for cf, so generally speaking you only have to do it once per resource
  • g

    Greg Brimble | Cloudflare Pages

    01/14/2022, 11:31 AM
    You also need to clone the Response there, in order for it to go in the cache and to be returned to the visitor.
  • g

    Greg Brimble | Cloudflare Pages

    01/14/2022, 11:32 AM
    And your check seems kinda odd:
    if (cached === undefined) return cached
  • g

    Greg Brimble | Cloudflare Pages

    01/14/2022, 11:33 AM
    Don’t you want the opposite of that? So if it is found in the cache, then return it?
  • d

    DomeQ

    01/14/2022, 5:22 PM
    not me trying to fix it for about 4 hours 🥲
  • c

    Cоlе

    01/14/2022, 6:44 PM
    ah it never occurred to me to clone the response 🤦‍♂️ that seems to have fixed it, thanks for your help, Greg!
  • c

    Cоlе

    01/14/2022, 6:58 PM
    now that that's out of the way, is it normal for wrangler to not use cache? I see:
  • c

    Cоlе

    01/14/2022, 6:59 PM
    it's there, but
    cache.match()
    just returns undefined
  • b

    bsam75

    01/14/2022, 11:41 PM
    If I have a route that is like
    path/to/script.php
    can I make a functions route for that? Would it be like
    /functions/path/to/script.php/index.js
    ? I think ive tried alot of different routes but havent found the right one yet
  • b

    bsam75

    01/14/2022, 11:46 PM
    nvm, thats right but i had the wrong syntax for the functions script
  • c

    Cоlе

    01/15/2022, 12:39 AM
    It's known to be wonky on windows
  • j

    Jacob | Pages

    01/15/2022, 4:30 PM
    I'm trying to migrate from a webpack worker to modules so that it can run in Pages functions. Is there an example somewhere for how to bundle npm modules in a
    _worker.js
    file in module format?
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2022, 6:35 PM
    webpack + ESM don't play together all too nicely. If you can, I'd consider migrating to esbuild or rollup.
  • c

    Cоlе

    01/15/2022, 10:15 PM
    ok, for anyone who's interested, I did a proper write-up on image generation https://github.com/Mexican-Man/cloudflare-workers-image-generation-example
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2022, 10:16 PM
    So cool! Any thought given to writing text yet? I've only seen that done with Rust. Do you know if upng.js or any other similar libraries support rendering text?
  • c

    Cоlе

    01/15/2022, 10:18 PM
    Not that I know of. I had to do numbers, so I just made pngs of 0-9. Although it could be possible; I haven't looked into fonts yet.
  • g

    Greg Brimble | Cloudflare Pages

    01/15/2022, 10:19 PM
    Ha, smart!
1...616263...392Latest