// Fedify 0.3.0 import { FreshContext } from "$fresh/server.ts"; import { federation } from "../federation.ts"; // Import the `Federation` object export async function handler(request: Request, context: FreshContext) { return await federation.handle(request, { contextData: undefined, // If the `federation` object finds a request not responsible for it // (i.e., not a federation-related request), it will call the `next` // provided by the Fresh framework to continue the request handling // by the Fresh: onNotFound: context.next.bind(context), // Similar to `onNotFound`, but slightly more tricky one. // When the `federation` object finds a request not acceptable type-wise // (i.e., a user-agent doesn't want JSON-LD), it will call the `next` // provided by the Fresh framework so that it renders HTML if there's some // page. Otherwise, it will simply return a 406 Not Acceptable response. // This kind of trick enables the Fedify and Fresh to share the same routes // and they do content negotiation depending on `Accept` header: async onNotAcceptable(_request: Request) { const response = await context.next(); if (response.status !== 404) return response; return new Response("Not acceptable", { status: 406, headers: { "Content-Type": "text/plain", Vary: "Accept", }, }); }, }); }
https://todon.eu/system/media_attachments/files/112/114/593/241/817/091/original/ee5921aaa515baa4.png