staff_data/apps/server/src/trpc/trpc.router.ts

26 lines
717 B
TypeScript
Raw Normal View History

2024-07-11 11:00:51 +08:00
import { INestApplication, Injectable } from '@nestjs/common';
import { TrpcService } from '@server/trpc/trpc.service';
import * as trpcExpress from '@trpc/server/adapters/express';
import { HelloRouter } from '@server/hello/hello.router';
@Injectable()
export class TrpcRouter {
constructor(private readonly trpc: TrpcService, private readonly hello: HelloRouter) { }
appRouter = this.trpc.router({
hello: this.hello.router
});
async applyMiddleware(app: INestApplication) {
app.use(
`/trpc`,
trpcExpress.createExpressMiddleware({
router: this.appRouter,
}),
);
}
}
export type AppRouter = TrpcRouter[`appRouter`];