Skip to content

feat: export http utils from nitro#4097

Merged
pi0 merged 2 commits into
mainfrom
feat/definehandler
Mar 11, 2026
Merged

feat: export http utils from nitro#4097
pi0 merged 2 commits into
mainfrom
feat/definehandler

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Mar 11, 2026

Using defineHandler is very common across Nitro apps. This PR adds a simple re-export of defineHandler from main subpath.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Mar 11, 2026 7:28am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

Updated many docs and example imports to use nitro instead of nitro/h3 and added re-exports (defineHandler, middleware, WS handlers, html, HTTPError/Response, H3Event) from h3 in src/runtime/nitro.ts. Small docs trimming and ui-code-tree ignore tweaks also included.

Changes

Cohort / File(s) Summary
Docs — quickstart / routing / renderer / lifecycle / tasks / assets / config / migration / deploy
docs/1.docs/2.quick-start.md, docs/1.docs/4.renderer.md, docs/1.docs/5.routing.md, docs/1.docs/6.server-entry.md, docs/1.docs/7.cache.md, docs/1.docs/50.*, docs/1.docs/99.migration.md, docs/2.deploy/20.providers/cloudflare.md
Replaced imports from "nitro/h3" with "nitro" in examples; switched some snippets to event.req.json() instead of readBody; minor example content trims.
Docs — examples collection
docs/4.examples/*, docs/4.examples/.../vite-*, docs/4.examples/.../websocket.md, docs/4.examples/cached-handler.md
Bulk update of example code blocks to import handlers/types from "nitro" (and some html/WS imports); removed several .gitignore/demo snippets.
Examples — projects and READMEs
examples/*, examples/.../api-routes/*, examples/.../auto-imports/*, examples/.../custom-error-handler/*, examples/.../database/*, examples/.../middleware/*, examples/.../nano-jsx/*, examples/.../renderer/*, examples/.../runtime-config/*, examples/.../server-fetch/*, examples/.../websocket/*, examples/.../cached-handler/*
Consistent update: import public H3 utilities (defineHandler, HTTPError, html, H3Event) from "nitro" instead of "nitro/h3" in source and README snippets; no logic changes.
Runtime — public re-exports
src/runtime/nitro.ts
Added re-exports from h3: defineHandler, defineMiddleware, defineWebSocketHandler, html, HTTPError, HTTPResponse, and type H3Event to expose these symbols from nitro.
Tooling config
automd.config.ts
Extended ui-code-tree ignore patterns to include README.md and dotfiles (.*).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title follows conventional commits format with a 'feat' type prefix and clearly describes the main change of exporting HTTP utilities from the nitro module.
Description check ✅ Passed The PR description is directly related to the changeset, explaining that defineHandler is commonly used and the PR adds re-exports of it from the main subpath.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/definehandler

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4097

commit: 2619ba7

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/runtime/nitro.ts (1)

15-17: Drop the new section comment.

The // H3 handler line is just restating the export and adds a new explanatory comment in src/, which this repo asks us to avoid.

✂️ Suggested cleanup
-
-// H3 handler
 export { defineHandler } from "h3";

As per coding guidelines, src/**/*.{js,ts,mjs,mts}: Do not add comments explaining what the line does unless prompted.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/runtime/nitro.ts` around lines 15 - 17, Remove the extraneous comment
line "// H3 handler" above the export; leave the existing export statement
"export { defineHandler } from \"h3\";" unchanged so the symbol defineHandler is
still re-exported from the h3 module and the file conforms to src/* comment
guidelines.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/1.docs/99.migration.md`:
- Around line 181-183: Update the migration example to show both the import
change and the handler wrapper rename: replace imports of
eventHandler/defineEventHandler with defineHandler and update exported handlers
to use defineHandler(...) instead of eventHandler(...) or
defineEventHandler(...); ensure the example includes an export default
defineHandler((event) => { ... }) snippet so readers see both the import and
call-site change.

In `@examples/auto-imports/server.ts`:
- Around line 1-4: The snippet still explicitly imports makeGreeting, so remove
the manual import line and let the auto-import feature provide makeGreeting;
specifically delete the import statement that references
"./server/utils/hello.ts" and keep the default export using defineHandler(() =>
`<h1>${makeGreeting("Nitro")}</h1>`), ensuring makeGreeting remains exported
from server/utils/hello.ts so the example demonstrates auto-imports correctly.

---

Nitpick comments:
In `@src/runtime/nitro.ts`:
- Around line 15-17: Remove the extraneous comment line "// H3 handler" above
the export; leave the existing export statement "export { defineHandler } from
\"h3\";" unchanged so the symbol defineHandler is still re-exported from the h3
module and the file conforms to src/* comment guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7bad120f-006d-47ce-ab46-6a0867162e34

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea3e15 and 7f0d154.

📒 Files selected for processing (44)
  • docs/1.docs/2.quick-start.md
  • docs/1.docs/4.renderer.md
  • docs/1.docs/5.routing.md
  • docs/1.docs/50.assets.md
  • docs/1.docs/50.configuration.md
  • docs/1.docs/50.database.md
  • docs/1.docs/50.lifecycle.md
  • docs/1.docs/50.tasks.md
  • docs/1.docs/6.server-entry.md
  • docs/1.docs/7.cache.md
  • docs/1.docs/99.migration.md
  • docs/2.deploy/20.providers/cloudflare.md
  • docs/4.examples/api-routes.md
  • docs/4.examples/auto-imports.md
  • docs/4.examples/custom-error-handler.md
  • docs/4.examples/database.md
  • docs/4.examples/middleware.md
  • docs/4.examples/nano-jsx.md
  • docs/4.examples/renderer.md
  • docs/4.examples/runtime-config.md
  • docs/4.examples/server-fetch.md
  • examples/api-routes/README.md
  • examples/api-routes/api/hello.ts
  • examples/api-routes/api/hello/[name].ts
  • examples/api-routes/api/test.get.ts
  • examples/api-routes/api/test.post.ts
  • examples/auto-imports/README.md
  • examples/auto-imports/server.ts
  • examples/custom-error-handler/README.md
  • examples/custom-error-handler/server.ts
  • examples/database/README.md
  • examples/database/server.ts
  • examples/middleware/README.md
  • examples/middleware/server.ts
  • examples/nano-jsx/README.md
  • examples/nano-jsx/server.tsx
  • examples/renderer/README.md
  • examples/renderer/api/hello.ts
  • examples/runtime-config/README.md
  • examples/runtime-config/server.ts
  • examples/server-fetch/README.md
  • examples/server-fetch/routes/hello.ts
  • examples/server-fetch/routes/index.ts
  • src/runtime/nitro.ts

Comment on lines 181 to 183
-- import { eventHandler, defineEventHandler } from "nitro/h3"
++ import { defineHandler } from "nitro/h3"
++ import { defineHandler } from "nitro"
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

In H3 v2 / Nitro v3 migration guidance, were eventHandleranddefineEventHandlerreplaced bydefineHandler, and what is the recommended before/after example for that migration?

💡 Result:

Yes. H3 v2 migration guidance deprecates eventHandler / defineEventHandler in favor of defineHandler (or just exporting a plain function handler). [1]

Before (H3 v1 / Nitro v2):

import { defineEventHandler } from "h3";

export default defineEventHandler((event) => {
  return { ok: true };
});

After (H3 v2 / Nitro v3):

import { defineHandler } from "nitro/h3"; // (or from "h3" if you're using H3 directly)

export default defineHandler((event) => {
  return { ok: true };
});

[1][2][3]

Sources: H3 v2 migration guide [1], Nitro v3 docs example using defineHandler [2], H3 “Event Handlers” docs [3].


Include the handler call-site rename in the migration example.

The diff currently shows only the import path change, but the actual migration also requires renaming the handler wrapper from eventHandler(...) or defineEventHandler(...) to defineHandler(...). Without this, users may update imports alone and leave broken handler calls in their code.

✏️ Suggested doc expansion
 ```diff
 -- import { eventHandler, defineEventHandler } from "nitro/h3"
 ++ import { defineHandler } from "nitro"
-```
+
+- export default eventHandler((event) => {
++ export default defineHandler((event) => {
++   // ...
++ })
+```
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/1.docs/99.migration.md` around lines 181 - 183, Update the migration
example to show both the import change and the handler wrapper rename: replace
imports of eventHandler/defineEventHandler with defineHandler and update
exported handlers to use defineHandler(...) instead of eventHandler(...) or
defineEventHandler(...); ensure the example includes an export default
defineHandler((event) => { ... }) snippet so readers see both the import and
call-site change.

Comment on lines +1 to 4
import { defineHandler } from "nitro";
import { makeGreeting } from "./server/utils/hello.ts";

export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

The auto-import example still uses a manual import.

Line 2 imports makeGreeting, so this snippet never demonstrates the feature it is supposed to showcase. Because this example is mirrored in the docs, keeping the explicit import makes the auto-import story misleading for copy-paste users.

💡 Suggested fix
 import { defineHandler } from "nitro";
-import { makeGreeting } from "./server/utils/hello.ts";
 
 export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { defineHandler } from "nitro";
import { makeGreeting } from "./server/utils/hello.ts";
export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`);
import { defineHandler } from "nitro";
export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/auto-imports/server.ts` around lines 1 - 4, The snippet still
explicitly imports makeGreeting, so remove the manual import line and let the
auto-import feature provide makeGreeting; specifically delete the import
statement that references "./server/utils/hello.ts" and keep the default export
using defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`), ensuring
makeGreeting remains exported from server/utils/hello.ts so the example
demonstrates auto-imports correctly.

@pi0 pi0 force-pushed the feat/definehandler branch from 7f0d154 to a8dd296 Compare March 11, 2026 07:26
@pi0 pi0 changed the title feat: export defineHandler from nitro feat: export http utils from nitro Mar 11, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
docs/1.docs/99.migration.md (1)

181-193: ⚠️ Potential issue | 🟡 Minor

Complete the handler migration example and narrow the root-export wording.

This still shows only the import replacement. For Nitro 2 → 3, readers also need the wrapper rename (eventHandler(...) / defineEventHandler(...)defineHandler(...)), and the surrounding H3 v2 prose should clarify that only selected helpers are re-exported from root nitro rather than “all H3 utilities.” Otherwise the guide encourages partial migrations and contradicts itself.

📝 Suggested doc update
 ### Handler Utils

 ```diff
 -- import { eventHandler, defineEventHandler } from "nitro/h3"
 ++ import { defineHandler } from "nitro"
+
+- export default eventHandler((event) => {
++ export default defineHandler((event) => {
++   // ...
++ })

</details>

  

```web
In Nitro v3 / H3 v2 migration guidance, should `eventHandler(...)` and `defineEventHandler(...)` be migrated to `defineHandler(...)`, and are `defineHandler` / `HTTPError` documented as root exports from `nitro` rather than only `nitro/h3`?

Based on learnings: Add migration notes for breaking changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/1.docs/99.migration.md` around lines 181 - 193, Update the migration
docs to show the full handler wrapper rename and clarify root-export scope:
replace the example import line with the new import (defineHandler from
"nitro"), change the example default export wrapper from eventHandler(...) or
defineEventHandler(...) to defineHandler(...), and add a brief note that only
selected H3 utilities like defineHandler and HTTPError are exported from the
root "nitro" (not all h3 helpers), referencing the symbols eventHandler,
defineEventHandler, defineHandler, HTTPError, and nitro/h3 so readers know which
helpers move or remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@docs/1.docs/99.migration.md`:
- Around line 181-193: Update the migration docs to show the full handler
wrapper rename and clarify root-export scope: replace the example import line
with the new import (defineHandler from "nitro"), change the example default
export wrapper from eventHandler(...) or defineEventHandler(...) to
defineHandler(...), and add a brief note that only selected H3 utilities like
defineHandler and HTTPError are exported from the root "nitro" (not all h3
helpers), referencing the symbols eventHandler, defineEventHandler,
defineHandler, HTTPError, and nitro/h3 so readers know which helpers move or
remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ecc0f920-f7c4-4250-9de3-bdb9f3fc4d3c

📥 Commits

Reviewing files that changed from the base of the PR and between 7f0d154 and a8dd296.

📒 Files selected for processing (27)
  • automd.config.ts
  • docs/1.docs/5.routing.md
  • docs/1.docs/50.tasks.md
  • docs/1.docs/7.cache.md
  • docs/1.docs/99.migration.md
  • docs/4.examples/cached-handler.md
  • docs/4.examples/custom-error-handler.md
  • docs/4.examples/database.md
  • docs/4.examples/middleware.md
  • docs/4.examples/nano-jsx.md
  • docs/4.examples/renderer.md
  • docs/4.examples/runtime-config.md
  • docs/4.examples/vite-rsc.md
  • docs/4.examples/vite-ssr-tss-react.md
  • docs/4.examples/vite-trpc.md
  • docs/4.examples/websocket.md
  • examples/cached-handler/README.md
  • examples/cached-handler/server.ts
  • examples/custom-error-handler/README.md
  • examples/custom-error-handler/server.ts
  • examples/middleware/README.md
  • examples/middleware/server/middleware/auth.ts
  • examples/nano-jsx/README.md
  • examples/nano-jsx/server.tsx
  • examples/websocket/README.md
  • examples/websocket/routes/_ws.ts
  • src/runtime/nitro.ts
💤 Files with no reviewable changes (3)
  • docs/4.examples/vite-rsc.md
  • docs/4.examples/vite-ssr-tss-react.md
  • docs/4.examples/vite-trpc.md
🚧 Files skipped from review as they are similar to previous changes (9)
  • docs/4.examples/database.md
  • docs/4.examples/middleware.md
  • docs/1.docs/5.routing.md
  • examples/nano-jsx/server.tsx
  • examples/custom-error-handler/README.md
  • docs/1.docs/50.tasks.md
  • docs/4.examples/renderer.md
  • docs/4.examples/nano-jsx.md
  • docs/1.docs/7.cache.md

@pi0 pi0 merged commit e1f0057 into main Mar 11, 2026
11 checks passed
@pi0 pi0 deleted the feat/definehandler branch March 11, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant