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

    Warlando

    01/13/2022, 9:43 PM
    Exact!
  • w

    Warlando

    01/13/2022, 9:44 PM
    so I need to run it in the following fashion?
    npx wrangler pages dev -- npm run dev
  • g

    Greg Brimble | Cloudflare Pages

    01/13/2022, 9:46 PM
    I think that should work, yeah. Then it's hopefully available at localhost:8788
  • w

    Warlando

    01/13/2022, 9:46 PM
    do you guys know if this is something which might change later on and either Svelte would run none Node env or if Cloudflare would have a Node env?
  • w

    Warlando

    01/13/2022, 9:46 PM
    because I read a post where Cloudflare said the workers support Nodejs
  • g

    Greg Brimble | Cloudflare Pages

    01/13/2022, 9:47 PM
    Unlikely Svelte make any changes, I imagine
  • w

    Warlando

    01/13/2022, 9:47 PM
    and it seams SveltKit is just generating a
    _worker.js
  • g

    Greg Brimble | Cloudflare Pages

    01/13/2022, 9:47 PM
    But yes, we're looking at Node polyfills that might make this easier
  • w

    Warlando

    01/13/2022, 9:48 PM
    I've followed it here: https://github.com/sveltejs/kit/issues/1377
  • w

    Warlando

    01/13/2022, 9:48 PM
    and it seems they're going on about on how to change the Cloudflare worker to support Node
  • w

    Warlando

    01/13/2022, 9:48 PM
    but I can't seem to follow it through
  • w

    Warlando

    01/13/2022, 9:59 PM
    unfortunately it does not work, even with Wrangler
  • w

    Warlando

    01/13/2022, 10:00 PM
    I found this: https://blog.cloudflare.com/node-js-support-cloudflare-workers/
  • w

    Warlando

    01/13/2022, 10:05 PM
    but there's no good enough explanation on how to run Node env
  • g

    Greg Brimble | Cloudflare Pages

    01/13/2022, 10:07 PM
    You can't at the moment. We're still exploring how best to get there.
  • c

    Cоlе

    01/13/2022, 10:35 PM
    @User so right now I'm using a ~200x300 image, painting an "full inventory" (as seen above) takes about 10-20ms, decoding the background takes about 1-20ms, and and encoding takes about ~3-30ms, so it's pretty fast
  • c

    Cоlе

    01/13/2022, 10:35 PM
    but it still takes more than one request
  • e

    Epailes

    01/13/2022, 10:37 PM
    Thanks for sharing, I thought doing something like that would be beyond the bundled 50ms. So you're doing this in a regular worker and just getting some rough benchmarks, then splitting it into different requests to get it all done. Makes sense and gets the job done, thanks for sharing all of this!
  • c

    Cоlе

    01/13/2022, 10:52 PM
    has anyone had any lucking using cache?
  • c

    Cоlе

    01/13/2022, 10:53 PM
    on wrangler, if I cache.put(), the function automatically returns an empty response
  • c

    Cоlе

    01/13/2022, 10:54 PM
    and on cloudflare, it just fails to deploy
  • g

    Greg Brimble | Cloudflare Pages

    01/13/2022, 11:23 PM
    Can you share more of the code you’re using?
  • c

    Cоlе

    01/13/2022, 11:47 PM
    Copy code
    js
    var cache: Cache;
    
    export const onRequestPost: PagesFunction<{}> = async ({ request, env }): Promise<Response> => {
      let cached = await cache.match(request);
      if (cached === undefined) {
        return cached;
      }
      // return other stuff
      cache.put(request, response);
    };
  • c

    Cоlе

    01/13/2022, 11:47 PM
    there's a trimmed down version of what I have
  • g

    Greg Brimble | Cloudflare Pages

    01/14/2022, 1:48 AM
    You need to first get the
    cache
    from
    caches.open()
    or
    caches.default
    . And
    cache.put()
    returns a void promise which you need to await
  • g

    Greg Brimble | Cloudflare Pages

    01/14/2022, 1:50 AM
    So you should
    Copy code
    jsexport const onRequestPost: PagesFunction<{}> = async ({ request, env, waitUntil }) => {
      const cache = caches.default
      const cached = await cache.match(request);
      if (cached) {
        return cached;
      }
      // return other stuff
      waitUntil(cache.put(request, response.clone()));
      return response;
    };
  • c

    Cоlе

    01/14/2022, 4:06 AM
    oh right sorry, I missed that in my example >.<
  • c

    Cоlе

    01/14/2022, 4:06 AM
    long day
  • c

    Cоlе

    01/14/2022, 4:07 AM
    Copy code
    js
    var cache: Cache;
    
    export const onRequestPost: PagesFunction<{}> = async ({ request, env }): Promise<Response> => {
      cache = cache || await caches.open('name');
      let cached = await cache.match(request);
      if (cached === undefined) {
        return cached;
      }
      // get data
      const response = new Response()
      await cache.put(request, response);
      return response;
    };
  • c

    Cоlе

    01/14/2022, 4:10 AM
1...606162...392Latest