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