@truxie/nitro
@truxie/nitro
Mount a truxie application inside Nitro / h3 — Nuxt server routes, or Nitro on its own.
npm install @truxie/nitro
// server/api/[...].ts
import {createControllerDispatcher} from '@truxie/nitro'
import {app} from '~/server/app'
export default createControllerDispatcher({app})
One catch-all handler serves every @Controller route, and every @WebSocketGateway upgrade on the same path — crossws peers are adapted to truxie's WsPeer, so a gateway is portable between adapters.
What it does
matchRoute, then the application's pipeline: middlewares → guards → pipes → interceptors → handler → filters. Body parsing goes through h3 (so urlencoded bodies decode), with @RawBody() and @FormData() honoured when the handler asks for them. A malformed JSON body is reported as a 400 rather than arriving as an empty object.
A returned Response is passed through, a redirect() becomes sendRedirect, and a status recorded by a filter is applied with setResponseStatus.
One handler, without a controller
For a single endpoint that does not want a controller class:
export default defineHandler(app, {guards: [AuthGuard]}, async ctx => {
return {ok: true}
})
It runs the same pipeline, including the application's global guards and filters.
MIT.
Related Packages
Nuxt adapter for ObjectStack — Nitro server routes for the ObjectStack REST API.
Generate h3 and Nitro route handlers from a Drizzle schema, one module per table...
Version History
| Version | Released | License |
|---|---|---|
| 0.1.3 | MIT | |
| 0.1.2 | MIT | |
| 0.1.1 | MIT |
Pre-releases (1)
| Version | Released | License |
|---|---|---|
| 0.1.0-test.6 | MIT |