https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • t

    Till

    08/13/2021, 5:17 PM
    I’d love to leverage DO with Worker Sites. What are the chances of this becoming a reality in the future? If not, I might need to migrate away 😓
  • h

    HardAtWork

    08/13/2021, 5:21 PM
    Oh, you are asking about module support in KV Asset-Handler?
  • t

    Till

    08/13/2021, 5:35 PM
    Yes. I have a site using KV asset handler for all HTML assets, but the site is also serving an API and I’d like to switch from using millions of KV requests (as my database) over to DO. Would be a lot faster I believe.
  • g

    Greg-McKeon

    08/13/2021, 9:30 PM
    @User
  • g

    Greg-McKeon

    08/13/2021, 9:32 PM
    soon™️
  • k

    kenton

    08/13/2021, 9:42 PM
    What's stopping you from using Durable Objects with Workers Sites?
  • h

    HardAtWork

    08/13/2021, 9:45 PM
    KV Asset-Handler doesn't yet support modules.
  • h

    HardAtWork

    08/13/2021, 9:46 PM
    Or not fully, from what I understood.
  • e

    Erwin

    08/13/2021, 9:56 PM
    You are probably very much aware of this, but this comes with absolutely zero guarantees, your milage is very much going to vary, etc disclaimers..
  • t

    Till

    08/13/2021, 10:11 PM
    What @User said: https://github.com/cloudflare/kv-asset-handler/pull/200
  • e

    Erwin

    08/14/2021, 12:47 AM
    Hey @lukeed, do you have some time next week to look this over together and figure out a way forward?
  • t

    Till

    08/14/2021, 12:48 AM
    Yes, 100%. I’ll send you a calendar link via DM now.
  • l

    lukeed

    08/14/2021, 12:56 AM
    @User i would prefer the core handler is abstracted elsewhere, and then the developer imports a method that is specific to their worker format
  • e

    Erwin

    08/14/2021, 12:56 AM
    That is always my preference too indeed.
  • e

    Erwin

    08/14/2021, 12:59 AM
    Is the issue that the event is propagated throughout the handler?
  • l

    lukeed

    08/14/2021, 12:59 AM
    Another option:
    Copy code
    ts
    // @cloudflare/kv-asset-handler
    export function getAssetFromKV(event: FetchEvent, options?: Options): Promise<Response>;
    
    // @cloudflare/kv-asset-handler/module
    export function getAssetFromKV(req: Context, ctx: Context, options?: Options): Promise<Response>;
  • l

    lukeed

    08/14/2021, 12:59 AM
    well, the
    FetchEvent
    is obliterated in a module worker
  • l

    lukeed

    08/14/2021, 12:59 AM
    and so all existing types/utils/etc are going to be expecting that type-match
  • e

    Erwin

    08/14/2021, 12:59 AM
    For good reasons yes 😂
  • l

    lukeed

    08/14/2021, 1:00 AM
    i disagree tbh, but beside the point
  • e

    Erwin

    08/14/2021, 1:00 AM
    Hehe.. I know 😉
  • l

    lukeed

    08/14/2021, 1:07 AM
    we still very much have a fetchevent, but its API is split up into pieces & littered across two objects. so another option could be:
    Copy code
    ts
    // hacky TS utility to reassemble a FetchEvent
    export function assemble(request: Request, ctx: Context): FetchEvent {
      return { ...ctx, request } as FetchEvent;
    }
    
    // ...
    
    export default {
      fetch(req, env, ctx) {
        if (req.url.startsWith('/static')) {
          let event = assemble(req, ctx);
          return getAssetFromKV(event, { ... });
        }
      }
    };
  • e

    Erwin

    08/14/2021, 1:11 AM
    The best Australian expression there is is "Yeah Nah".. which is my initial reaction..
  • e

    Erwin

    08/14/2021, 1:12 AM
    But.. uhh.. it is actually a pretty clean solution..
  • l

    lukeed

    08/14/2021, 1:12 AM
    i get it 😆 but it's not wrong
  • l

    lukeed

    08/14/2021, 1:12 AM
    those 2 ctx keys are fetchevent properties
  • l

    lukeed

    08/14/2021, 1:13 AM
    i am 10,000% doing this for my own projects
  • e

    Erwin

    08/14/2021, 1:14 AM
    Hehe... you luddite barbarian 😄
  • l

    lukeed

    08/14/2021, 1:15 AM
    haha im very much not a luddite, hence jumping onto workers so early on
  • e

    Erwin

    08/14/2021, 1:17 AM
    So you just can't let go of the past when it comes to workers? 😉
1...151152153...567Latest