docs: prefer fetch adapter for nuxtjs#1007
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughSwitched Nuxt adapter examples and playground routes from Node req/res handlers to Fetch API Request flow: import from Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests
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.
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. Comment |
There was a problem hiding this comment.
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/fetchhandler over the@orpc/server/nodehandler. - 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
-
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. ↩
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
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
📒 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 sandboxSandbox 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 || trueFile: 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.
There was a problem hiding this comment.
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
toWebRequestfromh3, 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
Responseis 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
📒 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
closes: #1005
Summary by CodeRabbit