Skip to content

Question about cloud edge functions support #161

Description

@elct9620

Hi,

I find the microblog document has some notes about Recently, cloud edge functions like Cloudflare Workers have also gained popularity as JavaScript runtimes

Does Fedify expect to support it natively?

If I choose to use Cloudflare Workers, I need to use the Bindings feature to get the key-value store.

interface Bindings {
  Cache: KVNamespace;
}

const app = new Hono<{ Bindings: Bindings }>()

// ...
app.use(federation(fedi, (ctx) => {
   // the "ctx.env.Cache" is here
  return // ...
}));  

However, the Federation object is required kv and initialized before handling the request.

const fedi = createFederation<string>({
  // ctx.env.Cache is not available yet
});

const app = new Hono();
app.use(federation(fedi, (ctx) => "context data"));  

Or the expected usage is like this

interface Bindings {
  Cache: KVNamespace;
}

const app = new Hono<{ Bindings: Bindings }>()

app.use(async (ctx, next) => {
  const fedi = createFederation<string>({
    kv: new MyKVStore(ctx.env.Cache)
  });
  
  ctx.set('fedi', fedi) // use this later

  await next()
});  

Metadata

Metadata

Assignees

No one assigned

    Labels

    component/kvKey–value store relateddiscussionNeeds discussionhelp wantedExtra attention is neededquestionFurther information is requestedruntime/cfworkersCloudflare Workers runtime related

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions