forked from wangziqi/gongxue-base
feat: migrate backend foundation to NestJS
This commit is contained in:
16
apps/api/src/nest/domain-route.service.ts
Normal file
16
apps/api/src/nest/domain-route.service.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import type { Handler } from '../core/http.js';
|
||||
import { RequestContextFactory } from './request-context.factory.js';
|
||||
|
||||
export abstract class DomainRouteService {
|
||||
protected constructor(
|
||||
protected readonly contextFactory: RequestContextFactory,
|
||||
private readonly handlers: Record<string, Handler>,
|
||||
) {}
|
||||
|
||||
execute(name: string, request: FastifyRequest, reply: FastifyReply) {
|
||||
const handler = this.handlers[name];
|
||||
if (!handler) throw new Error(`Missing domain route handler: ${name}`);
|
||||
return handler(this.contextFactory.create(request, reply));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user