fedify Main Island · East Shore

The Fourteen Bridges

ja· en· ko
If you're new hereA row of conversion adapters for connecting fedify to various web frameworks.

You add federation without leaving the framework you already use. hono, Express, Next, SvelteKit—import one bridge, and the same URL starts returning HTML to a browser and JSON-LD to a fedi client. No migration required.

The finesse of a bridge is in how it yields. If the errand isn't fedify's, it quietly hands off to the framework's next()—and with that one move, your existing routing and federation can share the same address.

Highlights

  • The bridge hollo crosses is the hono one (about 200 lines). A bridge this short is possible because fedify speaks in the web-standard Request/Response.
  • The nestjs bridge is a full DI module set (module + middleware + constants); the nuxt bridge is a Nuxt module with a runtime/ folder—the bridge's shape shifts to match each ecosystem's manners.

A passage from the sutra

export function federation<TContextData, THonoContext extends HonoContext>(
  federation: Federation<TContextData>,
  contextDataFactory: ContextDataFactory<TContextData, THonoContext>,
): HonoMiddleware<THonoContext> {
  return async (ctx, next) => {
    let contextData = contextDataFactory(ctx);
    if (contextData instanceof Promise) contextData = await contextData;
    return await federation.fetch(ctx.req.raw, {
      contextData,
      ...integrateFetchOptions(ctx, next),
    });
  };
}
packages/hono/src/mod.ts L58-L70— The full view of a single bridge, yielding and all

Floor plan

packages/hono/src/mod.ts
The representative one: the federation() middleware
packages/nestjs/src/fedify.module.ts
The same bridge, built the NestJS way
packages/express/src/index.ts
The Express-style one

Neighboring rooms

Outside links