Skip to content

docs: prefer fetch adapter for nuxtjs#1007

Merged
dinwwwh merged 2 commits into
mainfrom
unnoq/issue1005
Sep 16, 2025
Merged

docs: prefer fetch adapter for nuxtjs#1007
dinwwwh merged 2 commits into
mainfrom
unnoq/issue1005

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Sep 16, 2025

closes: #1005

Summary by CodeRabbit

  • Breaking Changes
    • Request handlers now use the Web Fetch API and return a response object; update integrations to the new handler signature.
  • New Features
    • Nuxt integration and example routes now use Fetch-based handlers for broader runtime compatibility (including edge).
  • Bug Fixes
    • API and RPC routes return explicit 404 responses when no endpoint matches.
  • Documentation
    • Nuxt adapter docs updated to reflect Fetch-based usage and revised handler patterns.

@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 16, 2025

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

Project Deployment Preview Comments Updated (UTC)
orpc Ready Ready Preview Comment Sep 16, 2025 4:20am

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 16, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 16, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Switched Nuxt adapter examples and playground routes from Node req/res handlers to Fetch API Request flow: import from @orpc/server/fetch, convert Nitro event with toWebRequest(event), call handler.handle(request, { prefix, context }), and branch on a returned { response } (emit it) or set 404.

Changes

Cohort / File(s) Summary
Docs: Nuxt adapter (Fetch-based API)
apps/content/docs/adapters/nuxt.md
Example updated to import from @orpc/server/fetch, use toWebRequest(event), call handler.handle(request, { prefix, context }), and check { response } instead of { matched }. Nuxt link and Nitro sentence adjusted.
Playground: Nuxt API route (OpenAPI via Fetch)
playgrounds/nuxt/server/routes/api/[...].ts
Switched OpenAPI handler import to Fetch variant, construct request via toWebRequest(event), call openAPIHandler.handle(request, { prefix: '/api', context }), return response if present; otherwise set 404 and return "Not Found".
Playground: Nuxt RPC route (RPC via Fetch)
playgrounds/nuxt/server/routes/rpc/[...].ts
Switched RPC handler import to @orpc/server/fetch, convert event with toWebRequest(event), call rpcHandler.handle(request, { prefix: '/rpc', context }), check { response } and return it or set 404.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant NuxtRoute as Nuxt Route
  participant Adapter as toWebRequest
  participant Handler as ORPC/OpenAPI Handler

  Client->>NuxtRoute: HTTP request (Nitro event)
  NuxtRoute->>Adapter: toWebRequest(event)
  Adapter-->>NuxtRoute: Fetch Request
  NuxtRoute->>Handler: handle(request, { prefix, context })
  alt Handler returns response
    Handler-->>NuxtRoute: { response }
    NuxtRoute-->>Client: response
  else No response
    NuxtRoute->>NuxtRoute: set 404 status
    NuxtRoute-->>Client: 404 Not Found
  end

  rect rgba(200,235,255,0.25)
  note right of Handler: Changed: Node req/res → Fetch Request\nReturn contract: matched → response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • unnoq/orpc#801 — Adds/adjusts fetch-based RPCHandler implementation and signature; strongly related to switching handler imports and call shape.
  • unnoq/orpc#295 — Alters handler matching/response semantics; related to moving from { matched } to { response }.
  • unnoq/orpc#583 — Modifies Nuxt server RPC route integrations and context handling; touches same playground route files.

Poem

I hop from req/res to Fetch with cheer,
A webby breeze across the Nuxt frontier.
If response arrives, I dart it near,
Else 404 — no carrot here.
A rabbit refactor, quick and clear. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning Linked issue #1005 reports a production bug where requests arrive as raw bytes under Nitro preset=bun and requests a fix or runtime option; this PR updates docs and Nuxt example routes to use the fetch-based handlers (toWebRequest + handler.handle(request,...)) but does not modify the Nuxt adapter implementation itself to handle Uint8Array bodies. Because the changes are limited to examples and documentation and do not implement an adapter-level fix or add a runtime option to address raw-body handling, the PR does not fully meet the linked issue's primary coding objective of resolving the 400 error in production. Therefore the linked-issue requirement is not satisfied by the current changeset. To fully address #1005, update the Nuxt adapter implementation to use the fetch handler or add explicit handling/conversion for raw Uint8Array request bodies inside the adapter, include a regression test reproducing the bun production scenario, and document the runtime behavior; if the intent is only to provide examples/workarounds, explicitly state that in the PR and issue so the bug remains tracked until an adapter-level fix is merged.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "docs: prefer fetch adapter for nuxtjs" concisely and accurately summarizes the primary change shown in the diff — updating Nuxt documentation and example playground routes to prefer the fetch-based adapter/handler flow instead of the node adapter. It is specific, short, and directly related to the modified files. The title is appropriate for history and review scanning.
Out of Scope Changes Check ✅ Passed The changes are limited to Nuxt documentation and the Nuxt playground routes (switching imports to @orpc/server/fetch, converting events to Web Requests, and updating handler usage) plus a small doc link update, all of which directly relate to preferring the fetch adapter to avoid the Nuxt/Nitro bun body-parsing issue. I do not see unrelated or extraneous modifications outside the stated objective. Thus the edits appear in-scope for the PR's stated goal of preferring the fetch adapter in docs and examples.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch unnoq/issue1005

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the Nuxt.js adapter documentation and its accompanying code example. The primary goal is to promote the use of the Fetch API-based RPC handler, offering a more standardized and potentially portable approach to integrating oRPC within Nuxt.js applications. The changes simplify the server setup by leveraging Web Request objects, ensuring a cleaner and more consistent integration pattern.

Highlights

  • Documentation Refinement: The documentation for the Nuxt.js adapter has been updated to remove a specific detail about Nuxt.js's underlying server technology, making the description more concise.
  • Fetch Adapter Preference: The example code for setting up an oRPC server within Nuxt.js now explicitly prefers the @orpc/server/fetch handler over the @orpc/server/node handler.
  • Web Request Integration: The server-side example has been modified to convert the Nuxt event into a standard Web Request using toWebRequest, aligning the RPC handling with modern Fetch API standards.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Nuxt.js adapter documentation to prefer the fetch adapter over the node adapter. This is a positive change that aligns with modern web standards. The updated code example, however, is missing an import which would cause it to fail. I've added a comment with a suggestion to fix this.

Comment thread apps/content/docs/adapters/nuxt.md
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Sep 16, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1007

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1007

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1007

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@1007

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1007

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1007

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1007

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1007

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1007

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1007

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1007

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1007

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1007

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1007

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1007

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1007

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1007

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1007

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1007

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1007

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1007

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1007

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1007

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1007

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1007

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1007

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1007

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1007

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1007

commit: b9574b6

Copy link
Copy Markdown

@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: 0

🧹 Nitpick comments (5)
playgrounds/nuxt/server/routes/rpc/[...].ts (1)

14-15: Add explicit h3 imports to avoid brittle auto-imports (toWebRequest, setResponseStatus).

Nuxt’s server auto-imports can regress or be disabled. Import explicitly to guarantee builds across presets/runtimes.

Apply:

 import { onError } from '@orpc/server'
 import { RPCHandler } from '@orpc/server/fetch'
+import { toWebRequest, setResponseStatus } from 'h3'
playgrounds/nuxt/server/routes/api/[...].ts (1)

66-67: Import h3 helpers explicitly (toWebRequest, getHeader, setResponseStatus).

Prevents breakage if server auto-imports are off or regress (seen in some Nitro versions).

Apply:

-import { OpenAPIHandler } from '@orpc/openapi/fetch'
+import { OpenAPIHandler } from '@orpc/openapi/fetch'
+import { toWebRequest, getHeader, setResponseStatus } from 'h3'

Also applies to: 73-77, 78-80

apps/content/docs/adapters/nuxt.md (3)

8-8: Fix outdated Nuxt link and naming.

Use Nuxt and nuxt.com (Nuxt 3/4 branding).

Apply:

-[Nuxt.js](https://nuxtjs.org/) is a popular Vue.js framework for building server-side applications. For more details, see the [HTTP Adapter](/docs/adapters/http) guide.
+[Nuxt](https://nuxt.com/) is a popular Vue framework for building server-side applications. For more details, see the [HTTP Adapter](/docs/adapters/http) guide.

17-17: Show explicit h3 imports in the sample for clarity.

Readers may copy/paste into environments where auto-imports are off; be explicit.

Apply:

 ```ts [server/routes/rpc/[...].ts]
-import { RPCHandler } from '@orpc/server/fetch'
+import { RPCHandler } from '@orpc/server/fetch'
+import { toWebRequest, setResponseStatus } from 'h3'
 
 const handler = new RPCHandler(router)
 
 export default defineEventHandler(async (event) => {
-  const request = toWebRequest(event)
+  const request = toWebRequest(event)
 
-  const { response } = await handler.handle(request, {
+  const { response } = await handler.handle(request, {
     prefix: '/rpc',
     context: {}, // Provide initial context if needed
   })


Also applies to: 22-27

---

`29-30`: **Minor copy tweak: 404 message casing.**

Use “Not Found” consistently (matches other examples).

Apply:

```diff
-  if (response) {
-    return response
+  if (response) {
+    return response
   }
 
   setResponseStatus(event, 404, 'Not Found')
-  return 'Not found'
+  return 'Not Found'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a1b696 and 6c446cc.

📒 Files selected for processing (3)
  • apps/content/docs/adapters/nuxt.md (2 hunks)
  • playgrounds/nuxt/server/routes/api/[...].ts (2 hunks)
  • playgrounds/nuxt/server/routes/rpc/[...].ts (2 hunks)
🔇 Additional comments (5)
playgrounds/nuxt/server/routes/rpc/[...].ts (3)

2-2: Switch to fetch adapter looks good.

Importing RPCHandler from @orpc/server/fetch is the right move for Bun/Nitro compatibility.


23-25: Returning a Web Response from the handler is correct.

H3/Nitro will adopt native Response instances; the control flow is sound.


14-15: Action: manual verification required — Bun not available in sandbox

Sandbox missing Bun (error: "/bin/bash: line 7: bun: command not found"); unable to run the repro. Run the repro below in an environment with Bun and confirm POST /rpc/health.check returns 200 (no 400).

#!/bin/bash
set -euo pipefail

# 1) Install & build
bun i
bun run build

# 2) Start production server
bun run .output/server/index.mjs & 
SRV_PID=$!
sleep 2

# 3) Probe RPC endpoint
curl -i -X POST "http://localhost:3000/rpc/health.check" \
  -H "content-type: application/json" \
  --data '{"jsonrpc":"2.0","id":1,"method":"health.check","params":{}}' || true

kill $SRV_PID || true

File: playgrounds/nuxt/server/routes/rpc/[...].ts (around lines 14–15 — const request = toWebRequest(event)).

playgrounds/nuxt/server/routes/api/[...].ts (2)

1-1: OpenAPI fetch adapter import is correct.

Aligns the API route with the fetch-based flow.


78-80: Response handling LGTM.

Returning Response when produced and falling back to 404 is correct.

Copy link
Copy Markdown

@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: 0

♻️ Duplicate comments (1)
apps/content/docs/adapters/nuxt.md (1)

17-23: Add missing import for toWebRequest (copy-paste blocker).

Without importing toWebRequest from h3, the snippet errors for users. This was already flagged previously and still applies.

- import { RPCHandler } from '@orpc/server/fetch'
+ import { RPCHandler } from '@orpc/server/fetch'
+ import { toWebRequest } from 'h3'
🧹 Nitpick comments (3)
apps/content/docs/adapters/nuxt.md (3)

24-27: Propagate request headers via context (auth/session-friendly).

Passing headers along is common for auth and tracing; easy win for realistic setups.

-  const { response } = await handler.handle(request, {
-    prefix: '/rpc',
-    context: {}, // Provide initial context if needed
-  })
+  const { response } = await handler.handle(request, {
+    prefix: '/rpc',
+    context: { headers: getRequestHeaders(event) }, // forward headers if needed
+  })

If you accept this, also extend the imports:

- import { toWebRequest } from 'h3'
+ import { toWebRequest, getRequestHeaders } from 'h3'

29-31: Consider sendWebResponse for widest Nitro compatibility (optional).

Returning a Web Response is fine on Nuxt 4/Nitro 2; sendWebResponse(event, response) is a belt‑and‑suspenders option for older environments.

-  if (response) {
-    return response
-  }
+  if (response) {
+    return response // or: return sendWebResponse(event, response)
+  }

8-8: Brand/style nit: “Nuxt” vs “Nuxt.js”.

Nuxt (v3+) styles itself as “Nuxt”. Consider “Nuxt is a popular Vue framework…”.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c446cc and b9574b6.

📒 Files selected for processing (1)
  • apps/content/docs/adapters/nuxt.md (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: publish-commit
  • GitHub Check: lint
  • GitHub Check: test

@dinwwwh dinwwwh merged commit 29a3f6d into main Sep 16, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ORPC server returns 400 on production with nuxt adapter when nitro preset = bun

1 participant