@truxie/next
v0.1.2
Published
Next.js adapter for truxie — controller dispatcher and execution context for App Router route handlers
Maintainers
Readme
@truxie/next
Mount a truxie application inside a Next.js App Router route handler.
npm install @truxie/next// app/api/[[...path]]/route.ts
import {createNextDispatcher} from '@truxie/next'
import {app} from '@/server/app'
const handler = createNextDispatcher({app})
export const GET = handler
export const POST = handler
export const PUT = handler
export const PATCH = handler
export const DELETE = handlerOne catch-all file serves every @Controller route. A per-route file works too, if the file-based routes are already there — export the same handler from it.
What it does
matchRoute against the request pathname, then the application's own pipeline: middlewares → guards → pipes → interceptors → handler → filters. The body is parsed according to the decorators the handler actually uses, so @RawBody() gets the exact bytes a webhook signature is computed over, @FormData() gets parsed multipart, and everything else gets JSON.
A handler that returns a Response has it returned untouched; anything else is JSON-encoded with the status a filter recorded, defaulting to 200. A redirect (redirect('/somewhere')) becomes a 302.
Client addresses
Serverless platforms terminate the connection themselves, so trustProxy defaults to on there and @Ip() reads the platform's forwarding header. On a self-hosted Next.js behind your own proxy, say so explicitly:
TruxieFactory.create(AppModule, {trustProxy: true})Without it, a forwarded address is not believed — it is chosen by the caller.
MIT.
