Files
stats/apps/api/src/routes/ai.router.ts
2025-04-15 14:30:21 +02:00

29 lines
672 B
TypeScript

import * as controller from '@/controllers/ai.controller';
import { activateRateLimiter } from '@/utils/rate-limiter';
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
const aiRouter: FastifyPluginCallback = async (fastify) => {
await activateRateLimiter<
FastifyRequest<{
Querystring: {
projectId: string;
};
}>
>({
fastify,
max: process.env.NODE_ENV === 'production' ? 20 : 100,
timeWindow: '300 seconds',
keyGenerator: (req) => {
return req.query.projectId;
},
});
fastify.route({
method: 'POST',
url: '/chat',
handler: controller.chat,
});
};
export default aiRouter;