Add Nuxt as a web framework option in fedify init#675
Add Nuxt as a web framework option in fedify init#6752chanhaeng wants to merge 31 commits intofedify-dev:mainfrom
fedify init#675Conversation
|
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:
📝 WalkthroughWalkthroughAdds a new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant NuxtModule as Nuxt Module / Middleware
participant Fedify as Fedify (federation.fetch)
participant Framework as Nuxt / App Route Handler
participant NitroPlugin as Nitro BeforeResponse Hook
Client->>NuxtModule: HTTP Request (may include Accept header)
NuxtModule->>NuxtModule: toWebRequest(), compute contextData?
NuxtModule->>Fedify: federation.fetch(request, contextData) (onNotFound/onNotAcceptable handlers registered)
alt Fedify handled
Fedify->>NuxtModule: Response (200/2xx/other)
NuxtModule->>Client: Return Fedify Response
else Fedify not-found
Fedify->>NuxtModule: sentinel 404
NuxtModule->>Framework: Delegate to framework next handler
Framework->>NuxtModule: Framework Response (404 or 2xx)
NuxtModule->>NitroPlugin: set deferred flag if onNotAcceptable triggered
NitroPlugin->>NuxtModule: resolveDeferredNotAcceptable(deferred, frameworkStatus, routeHandled)
alt resolved 406
NitroPlugin->>Client: Return 406 Not Acceptable (Vary: Accept)
else no override
NuxtModule->>Client: Return Framework Response
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~65 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces the @fedify/nuxt package to provide seamless integration between Fedify and the Nuxt framework, alongside updates to the fedify init tool for project scaffolding. The review feedback correctly identifies a critical bug in the Nuxt middleware template where the request body is ignored during manual Request construction, suggesting the use of toWebRequest from h3 as a fix. Furthermore, the feedback recommends enabling the @fedify/nuxt module by default in generated projects to simplify the setup and points out a typo in the Node.js type definitions version.
packages/init/src/templates/nuxt/server/middleware/federation.ts.tpl
Outdated
Show resolved
Hide resolved
packages/init/src/templates/nuxt/server/middleware/federation.ts.tpl
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
950c914 to
b4369b3
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.agents/skills/create-example-app-with-integration/SKILL.md:
- Around line 178-182: Change the hard-coded curl example that uses
"localhost:0000" to a parameterized form so users must supply the correct host
and port; update the example text in SKILL.md (the curl example block) to use a
clear placeholder such as "{HOST}:{PORT}" or "${HOST}:${PORT}" and mention a
sensible default (e.g., localhost:3000) so readers can copy/paste and
substitute their actual port before running the curl command.
In `@packages/init/src/templates/nuxt/server/middleware/federation.ts.tpl`:
- Around line 13-16: The middleware currently sets the request "body" to
undefined for all methods because the ternary always returns undefined; update
the federation middleware so that when event.node.req.method is NOT in
["GET","HEAD","DELETE"] you read and forward the actual request payload (e.g.,
await readBody(event) or the equivalent helper) into the body field instead of
undefined, and ensure the same content-type is preserved when calling the Fedify
endpoint (reference the body: property and event.node.req.method in the
federation middleware).
In `@packages/init/src/test/port.ts`:
- Around line 148-157: The code inserts nitro.port into nuxt.config.ts but
Nuxt's dev server port is controlled by devServer.port; change the replacement
so that defineNuxtConfig({ includes `devServer: { port: ${newPort} },` instead
of `nitro: { port: ${newPort} },` (affecting the writeFile call that replaces
"defineNuxtConfig({"). Also update the nearby comment that currently mentions
"Insert server.port into the Nuxt config (via nitro config in nuxt.config.ts)"
to accurately say it inserts devServer.port for the Nuxt dev server; keep
references to wf, configPath, readFile, writeFile, newPort and defineNuxtConfig
to locate the change.
In `@packages/init/src/webframeworks/nuxt.ts`:
- Around line 70-83: getDeps currently omits installing the peer dependency
`@nuxt/kit` for non-Deno package managers, causing unmet peer warnings; update the
non-Deno branch of getDeps (the ternary branch that returns "@fedify/nuxt",
"h3", "nuxt") to also include "@nuxt/kit": deps["npm:`@nuxt/kit`"] (mirroring the
Deno branch), keeping PACKAGE_VERSION and defaultDenoDependencies untouched so
that PackageManager handling and Deno-specific entries remain the same.
- Around line 61-68: getNuxtInitCommand currently invokes unpinned nuxi (e.g.,
"npm:nuxi@latest" or bare "nuxi"); update it to use the pinned nuxi version from
deps.json (use the same helper that exposes pinned versions, e.g., getDeps() or
the deps object) so every branch uses nuxi@<pinnedVersion>. Concretely, obtain
the pinned nuxi version (e.g., const { nuxi } = getDeps()) and interpolate it
into the command strings: for bun use ["bunx", `nuxi@${nuxi}`], for deno use
["deno", "-A", `npm:nuxi@${nuxi}`], for npm use ["npx", `nuxi@${nuxi}`], and for
other package managers use [pm, "dlx", `nuxi@${nuxi}`]; update
getNuxtInitCommand to reference that pinned variable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: bd865655-4bd8-49e6-9fd3-c3268f58142d
⛔ Files ignored due to path filters (2)
deno.lockis excluded by!**/*.lockpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (35)
.agents/skills/add-to-fedify-init/SKILL.md.agents/skills/create-example-app-with-integration/SKILL.md.agents/skills/create-example-app-with-integration/example/README.md.agents/skills/create-example-app-with-integration/example/src/logging.ts.agents/skills/create-integration-package/SKILL.md.hongdown.tomlAGENTS.mdCHANGES.mdCONTRIBUTING.mdcspell.jsondeno.jsondocs/manual/integration.mdmise.tomlpackages/fedify/README.mdpackages/init/src/const.tspackages/init/src/json/deps.jsonpackages/init/src/templates/nuxt/nuxt.config.ts.tplpackages/init/src/templates/nuxt/server/federation.ts.tplpackages/init/src/templates/nuxt/server/logging.ts.tplpackages/init/src/templates/nuxt/server/middleware/federation.ts.tplpackages/init/src/test/port.tspackages/init/src/webframeworks/mod.tspackages/init/src/webframeworks/nuxt.tspackages/nuxt/README.mdpackages/nuxt/deno.jsonpackages/nuxt/package.jsonpackages/nuxt/src/mod.test.tspackages/nuxt/src/mod.tspackages/nuxt/src/module.tspackages/nuxt/src/runtime/server/lib.tspackages/nuxt/src/runtime/server/logic.tspackages/nuxt/src/runtime/server/middleware.tspackages/nuxt/src/runtime/server/plugin.tspackages/nuxt/tsdown.config.tspnpm-workspace.yaml
packages/init/src/templates/nuxt/server/middleware/federation.ts.tpl
Outdated
Show resolved
Hide resolved
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/init/src/templates/nuxt/nuxt.config.ts.tpl`:
- Line 4: Update the fedify configuration in the template so the
federationModule path uses a single tilde; specifically change the
fedify.federationModule value from "~~/server/federation" to
"~/server/federation" in nuxt.config.ts.tpl to match the `@fedify/nuxt` defaults
and docs.
In `@packages/init/src/webframeworks/nuxt.ts`:
- Around line 70-78: The Deno branch of getDeps currently omits the npm-scoped
peer dependency required by `@fedify/nuxt`; update the Deno case in getDeps to
include the explicit mapping for `@nuxt/kit` by merging defaultDenoDependencies
with an entry for "@nuxt/kit" using the pinned value from deps (e.g.
deps["npm:`@nuxt/kit`"]) alongside the existing "@fedify/nuxt": PACKAGE_VERSION so
Deno will resolve the peer dependency correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c0e3750d-63cf-4b3b-aa48-1e3d99d056e5
📒 Files selected for processing (4)
packages/init/src/templates/nuxt/nuxt.config.ts.tplpackages/init/src/test/lookup.tspackages/init/src/test/port.tspackages/init/src/webframeworks/nuxt.ts
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.agents/skills/create-integration-package/SKILL.md:
- Around line 64-65: Replace the incorrect phrase "Use this commands" in
SKILL.md with "Use these commands" (locate the sentence containing "the
directory you created. Use this commands in the root path:") to fix grammar;
ensure the surrounding sentence remains unchanged except for that word
substitution.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 05538584-ad26-4a4b-8850-ffd1237469db
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (17)
.agents/skills/create-example-app-with-integration/example/README.md.agents/skills/create-integration-package/SKILL.mdCHANGES.mdpackages/init/src/const.tspackages/init/src/json/deps.jsonpackages/init/src/templates/nuxt/nuxt.config.ts.tplpackages/init/src/test/lookup.tspackages/init/src/test/port.tspackages/init/src/webframeworks/mod.tspackages/init/src/webframeworks/nuxt.tspackages/nuxt/package.jsonpackages/nuxt/src/module.test.tspackages/nuxt/src/module.tspackages/nuxt/src/runtime/server/logic.test.tspackages/nuxt/src/runtime/server/logic.tspackages/nuxt/src/runtime/server/plugin.test.tspackages/nuxt/src/runtime/server/plugin.ts
| the directory you created. Use this commands in the root path: | ||
|
|
There was a problem hiding this comment.
Fix grammar in command instruction sentence.
“Use this commands” should be “Use these commands”.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.agents/skills/create-integration-package/SKILL.md around lines 64 - 65,
Replace the incorrect phrase "Use this commands" in SKILL.md with "Use these
commands" (locate the sentence containing "the directory you created. Use this
commands in the root path:") to fix grammar; ensure the surrounding sentence
remains unchanged except for that word substitution.
da19758 to
bb22a01
Compare
|
@2chanhaeng review |
- Use @fedify/fixture instead of node:test in mod.test.ts - Type event parameter as H3Event instead of unknown in middleware.ts Co-Authored-By: Claude (claude-opus-4-20250514)
Move NOT_ACCEPTABLE_BODY and DEFERRED_NOT_ACCEPTABLE_CONTEXT_KEY into a shared lib.ts to avoid string duplication across logic.ts and plugin.ts. Co-Authored-By: Claude (claude-opus-4-20250514)
…chema` to `@fedify/nuxt`
- Use en dash instead of hyphen in example README template
title ("Fedify–프레임워크")
- Wrap HTTP status codes in backticks and use official reason
phrases in SKILL.md headings ("404 Not Found",
"406 Not Acceptable")
- Capitalize "Acceptable" in CHANGES.md to match the official
HTTP status phrase
fedify-dev#674
Assisted-by: GitHub Copilot:claude-opus-4.6
The test file imports from @fedify/fixture but it was missing from devDependencies, which would cause ERR_MODULE_NOT_FOUND in a clean install when running Node.js tests. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
Add failing tests that reproduce four bugs identified in PR review comments: - logic.test.ts: handler-returned 406 is misclassified as "not-acceptable" instead of "handled" (review fedify-dev#5) - logic.test.ts: framework's intentional 404 on shared routes is rewritten to 406 by resolveDeferredNotAcceptable (review fedify-dev#6) - module.test.ts: resolveAlias does not resolve plain relative paths to absolute, breaking .nuxt/ imports (review fedify-dev#7) - module.test.ts: missing default/contextDataFactory exports silently return undefined instead of throwing (review fedify-dev#9) All four tests fail against the current implementation and will pass once the corresponding bugs are fixed. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6 Add regression tests for PR review issues Add regression tests for PR review issues
Replace the status-code-based check (response.status === 406) with an identity comparison against the synthetic response created by the onNotAcceptable callback. This prevents genuine handler-returned 406 responses from being misclassified as "not-acceptable". The fix mirrors the existing pattern used for not-found detection, where DUMMY_NOT_FOUND_RESPONSE is compared by reference. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
Add a routeHandled parameter to resolveDeferredNotAcceptable so that it can distinguish a framework's intentional 404 (e.g., a matched page returning "user not found") from a genuine route miss. When routeHandled is true, the framework's 404 is preserved instead of being rewritten to 406. The plugin now passes event.context.matchedRoute to detect whether a Nitro route handler processed the request. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
resolveAlias() only expands aliases like ~ and @, leaving plain relative paths (./server/federation) unchanged. These paths then resolve against .nuxt/ at runtime instead of the project root, causing ERR_MODULE_NOT_FOUND. Add resolveModulePath() that wraps resolveAlias and falls back to path.resolve() against nuxt.options.rootDir for non-absolute results. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
When contextDataFactoryModule is configured but exports neither a default function nor a named contextDataFactory, the resolver previously set contextDataFactory to undefined silently. This made misconfiguration hard to detect. Now it throws a descriptive TypeError when both exports are missing, matching the existing behavior for non-function exports. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
Add plugin-level tests for the Nuxt beforeResponse hook. The new coverage verifies deferred 404 responses are rewritten to 406, ordinary 404 responses are left untouched when no deferred flag is present, and shared-route 404 responses remain unchanged when Nuxt matched the route. fedify-dev#674 Assisted-by: GitHub Copilot:GPT-5.4
When resolveAlias() passes through a bare package specifier like "@acme/federation" unchanged, the previous code resolved it against rootDir, producing an invalid filesystem path such as "/app/@acme/federation". Now only explicit relative paths (./ or ../) are resolved against rootDir. Bare specifiers are returned as-is so the bundler can resolve them from node_modules. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
Add a TContextData type parameter (defaulting to unknown) so that typed context data produced by ContextDataFactory flows through the fetcher signature end-to-end instead of being erased to unknown at the helper boundary. fedify-dev#674 Assisted-by: GitHub Copilot:claude-opus-4.6
Add Nuxt as a web framework option in
fedify initDepends on #674.
Changes
@fedify/initfedify init.Users can now scaffold a new Fedify project with Nuxt integration
across all supported package managers (npm, pnpm, yarn, Bun, Deno).
New files
src/webframeworks/nuxt.ts:WebFrameworkDescriptionfor Nuxt,including
nuxi initscaffolding command, dependency resolution forboth Node.js and Deno environments, and template file mapping.
src/templates/nuxt/nuxt.config.ts.tpl: Minimal Nuxt configtemplate with SSR disabled and devtools enabled.
src/templates/nuxt/server/federation.ts.tpl: Federationinstance setup with
MemoryKvStoreand a basic actor dispatcher.src/templates/nuxt/server/logging.ts.tpl: LogTapeconfiguration for Nuxt and Fedify loggers.
src/templates/nuxt/server/middleware/federation.ts.tpl: Nitroevent handler that delegates requests to
federation.fetch(),falling through to Nuxt on 404.
Modified files
src/const.ts: Added"nuxt"to theWEB_FRAMEWORKarray.src/webframeworks/mod.ts: Imported and registered the Nuxtframework description.
src/json/deps.json: Added@nuxt/kit,h3,nuxi, andnuxtversion pins.src/test/port.ts: Added port replacement logic for Nuxt(injects
nitro.portintonuxt.config.ts).Co-Authored-By: GPT-5.4