0.14.1 • Published 3 months ago
@spectrajs/trpc v0.14.1
@spectrajs/trpc
A plugin for Spectra that provides tRPC support.
Installation
npm install @spectrajs/trpc
Documentation
The documentation is available here.
Example
import { trpc } from "@spectrajs/trpc";
import { initTRPC } from "@trpc/server";
import { Spectra } from "@spectrajs/core";
const t = initTRPC.create();
const p = t.procedure;
const router = t.router({
greet: p.input(String).query(({ input }) => `Hello ${input}!`),
});
const app = new Spectra();
app.use(
"/trpc/*",
trpc({
router,
})
);
API
trpc
router
The tRPC Router instance.
endpoint
The path to the exposed tRPC endpoint.
@default /trpc
app.use(
"/api/trpc/*",
trpc({
endpoint: "/api/trpc",
router,
})
);
createContext
Create custom tRPC context.
app.use(
"/trpc/*",
trpc({
router,
createContext: (c, _opts) => ({
message: c.req.header("X-Message"),
}),
})
);
License
Distributed under the MIT License. See LICENSE for more information.