Nitro
Use Silgi with Nitro v3 — as the server framework (like Hono) or alongside H3 routes.
Nitro is the server engine behind Nuxt and TanStack Start. Silgi integrates with Nitro in two ways: as the server framework (replacing H3, like Hono does) or alongside H3 file-system routes.
Direct mode (recommended)
Just like Hono with Nitro, export an object with a fetch method from server.ts. Nitro detects it and uses Silgi as the server framework:
// server.ts
import { , } from 'silgi'
import { } from 'zod'
const = ({
: () => ({
: getDB(),
: .(.),
}),
})
const { , , } =
const = .(() => ({ : 'ok' }))
const = k
.$input(.({ : .().() }))
.$resolve(({ , }) => .db.users.findMany({ : .limit }))
const = ({ , : { : } })
// Export with fetch — Nitro uses it directly
export default { : () }No H3, no file-system routing, no silgiNitro adapter — Silgi IS the framework. Full content negotiation (JSON, MessagePack, devalue) works out of the box.
POST /health → { status: "ok" }
POST /users/list → [{ id: 1, name: "Alice" }, ...]This is the same pattern Hono uses with Nitro. Nitro detects the fetch method on the default export and routes all
requests through it.
H3 mode
If you need Nitro's file-system routing or want to mix Silgi with H3 routes, use the silgiNitro adapter:
// server/routes/rpc/[...path].ts
import { } from 'silgi/nitro'
import { } from '~/server/rpc'
export default (, {
: () => ({
: getDB(),
: ..,
}),
})Nitro maps [...path] to the procedure path:
POST /rpc/users/list → users/list
POST /rpc/users/create → users/createContext from Nitro middleware
// server/middleware/auth.ts
import { } from 'nitro/h3'
export default (() => {
.. = verifyToken(...('authorization'))
})// server/routes/rpc/[...path].ts
export default silgiNitro(appRouter, {
: () => ({
: .context.auth,
}),
})Which mode to choose?
| Scenario | Mode |
|---|---|
| New project, Silgi is the only framework | Direct ({ fetch: handler() }) |
| Existing Nitro/Nuxt app, adding RPC | H3 (silgiNitro()) |
| Need H3 middleware (auth, session, etc.) | H3 |
| Want full protocol support (msgpack, devalue, SSE) | Direct |
Both modes target Nitro v3 (H3 v2). For Nitro v2 (Nuxt 3), use the H3 adapter instead.
Examples
Working examples in the repo:
examples/nitro— direct modeexamples/nitro-h3— H3 file-system routing
What's next?
- H3 — lower-level H3 v2 adapter
- Server — standalone
serve()with full protocol support - Integrations — other available integrations