Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces the @fedify/nuxt package for Nuxt integration, including an example application and support in the fedify init command. Feedback points out a bug in manual request construction within the templates and suggests using h3's toWebRequest utility for better reliability. Additionally, the reviewer recommends correcting a version typo in Node.js types, enabling SSR by default to ensure ActivityPub compatibility, and refactoring the fedify init scaffolding to use the Nuxt module instead of manual middleware.
| import { defineEventHandler } from "h3"; | ||
| import federation from "../federation"; | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| // Construct the full URL from headers | ||
| const proto = event.headers.get("x-forwarded-proto") || "http"; | ||
| const host = event.headers.get("host") || "localhost"; | ||
| const url = new URL(event.node.req.url || "", `${proto}://${host}`); | ||
|
|
||
| const request = new Request(url, { | ||
| method: event.node.req.method, | ||
| headers: event.node.req.headers as Record<string, string>, | ||
| body: ["GET", "HEAD", "DELETE"].includes(event.node.req.method) | ||
| ? undefined | ||
| : undefined, | ||
| }); | ||
|
|
||
| const response = await federation.fetch(request, { | ||
| contextData: undefined, | ||
| }); | ||
|
|
||
| if (response.status === 404) return; // Let Nuxt handle 404 | ||
| return response; | ||
| }); |
There was a problem hiding this comment.
The manual construction of the Request object has a bug where the body is always undefined (lines 13-15), which will break incoming ActivityPub activities (POST requests). Additionally, manual URL reconstruction is error-prone. It is highly recommended to use h3's toWebRequest(event) utility, which correctly handles headers, methods, and bodies across different runtimes and ensures the host/port are preserved correctly.
import { defineEventHandler, toWebRequest } from "h3";
import federation from "../federation";
export default defineEventHandler(async (event) => {
const request = toWebRequest(event);
const response = await federation.fetch(request, {
contextData: undefined,
});
if (response.status === 404) return; // Let Nuxt handle 404
return response;
});
References
- When reconstructing a URL from a request object, prefer using methods that preserve the host and port (like the Host header) to ensure functionality like federation signature verification remains intact.
| devDependencies: { | ||
| ...defaultDevDependencies, | ||
| "typescript": deps["npm:typescript"], | ||
| "@types/node": deps["npm:@types/node@25"], |
There was a problem hiding this comment.
The key npm:@types/node@25 appears to be a typo and is likely missing from packages/init/src/json/deps.json. Node.js version 25 is not yet released. This should probably refer to a current version like @types/node@22 or simply @types/node as defined in the dependencies catalog.
"@types/node": deps["npm:@types/node"],| @@ -0,0 +1,5 @@ | |||
| // https://nuxt.com/docs/api/configuration/nuxt-config | |||
| export default defineNuxtConfig({ | |||
| ssr: false, | |||
There was a problem hiding this comment.
Setting ssr: false (Single Page Application mode) is generally inappropriate for federated applications. ActivityPub requires the server to respond with JSON-LD to actors, often on the same routes that serve HTML to browsers. Disabling SSR can complicate content negotiation and discovery. It is better to default to ssr: true, as seen in the example application.
ssr: true,
| "nuxt.config.ts": await readTemplate("nuxt/nuxt.config.ts"), | ||
| "server/federation.ts": await readTemplate("nuxt/server/federation.ts"), | ||
| "server/logging.ts": await readTemplate("nuxt/server/logging.ts"), | ||
| "server/middleware/federation.ts": await readTemplate( | ||
| "nuxt/server/middleware/federation.ts", | ||
| ), |
There was a problem hiding this comment.
The fedify init setup for Nuxt is currently inconsistent. It adds @fedify/nuxt to the dependencies but then manually sets up a Nitro middleware in server/middleware/federation.ts. It would be much cleaner and more idiomatic to enable the @fedify/nuxt module in the nuxt.config.ts template and remove the manual middleware file. This avoids redundancy and leverages the module's built-in features like deferred 406 handling.
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Add Nuxt example application
Depends on #675.
Changes
New example:
examples/nuxt/A comprehensive Nuxt example app demonstrating
@fedify/nuxtintegration with ActivityPub federation, following the standard
Fedify example architecture.
Features
object dispatcher for Notes, followers collection, NodeInfo, and
key pair management via
server/federation.ts.lists, user search, and SSE-powered live updates (
pages/index.vue);actor profile page (
pages/users/[identifier]/index.vue); postdetail page (
pages/users/[identifier]/posts/[id].vue).server/api/forhome data, posting, follow/unfollow, search, profile lookup, post
detail, and SSE events.
and dark/light theme toggle script in
public/.@fedify/nuxtmodule wired withfederation module path, open host/vite config for tunnel
compatibility.
@fedify/nuxtbugfixaddTemplate()withaddServerTemplate()inpackages/nuxt/src/mod.tsto ensure the generated federationmiddleware module is available in the Nitro server bundle rather
than only in the client build output.
Test integration
examples/test-examples/mod.tswithpnpm build+pnpm startworkflow and 30-second ready timeout.Co-Authored-By: Claude Opus 4.6