Transferred ShieldAI-related files mistakenly placed in ~/code/FrenoCorp:
- Services: spamshield (feature-flags, audit-logger, error-handler), voiceprint (config, service, feature-flags), darkwatch (pipeline, scan, scheduler, watchlist, webhook)
- Packages: shared-analytics, shared-auth, shared-ui, shared-utils (new); shared-billing, jobs supplemented with unique FC files
- Server: alerts (FC version newer), routes (spamshield, darkwatch, voiceprint)
- Config: turbo.json, tsconfig.base.json, vite/vitest configs, drizzle, Dockerfile
- VoicePrint ML service
- Examples
Pending: apps/{api,web,mobile}/ structured merge, shared-db/db mapping
Co-Authored-By: Paperclip <noreply@paperclip.ing>
143 lines
4.3 KiB
TypeScript
143 lines
4.3 KiB
TypeScript
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
|
import { authMiddleware, AuthRequest } from './auth.middleware';
|
|
import { voiceprintRoutes } from './voiceprint.routes';
|
|
import { spamshieldRoutes } from './spamshield.routes';
|
|
import { darkwatchRoutes } from './darkwatch.routes';
|
|
|
|
export async function routes(fastify: FastifyInstance) {
|
|
// Authenticated routes group
|
|
fastify.register(
|
|
async (authenticated) => {
|
|
// Add auth requirement
|
|
authenticated.addHook('onRequest', async (request: FastifyRequest, reply: FastifyReply) => {
|
|
await fastify.requireAuth(request as AuthRequest);
|
|
});
|
|
|
|
// Example authenticated endpoint
|
|
authenticated.get('/user/me', async (request: FastifyRequest, reply: FastifyReply) => {
|
|
const authReq = request as AuthRequest;
|
|
return {
|
|
user: authReq.user,
|
|
authType: authReq.authType,
|
|
};
|
|
});
|
|
|
|
// Example service endpoint
|
|
authenticated.get('/services', async (request: FastifyRequest, reply: FastifyReply) => {
|
|
return {
|
|
services: [
|
|
{
|
|
name: 'user-service',
|
|
url: '/api/v1/services/user',
|
|
status: 'healthy',
|
|
},
|
|
{
|
|
name: 'billing-service',
|
|
url: '/api/v1/services/billing',
|
|
status: 'healthy',
|
|
},
|
|
{
|
|
name: 'notification-service',
|
|
url: '/api/v1/services/notifications',
|
|
status: 'healthy',
|
|
},
|
|
],
|
|
};
|
|
});
|
|
},
|
|
{ prefix: '/auth' }
|
|
);
|
|
|
|
// Public API routes
|
|
fastify.register(
|
|
async (publicRouter) => {
|
|
// Version info
|
|
publicRouter.get('/info', async () => {
|
|
return {
|
|
version: '1.0.0',
|
|
environment: process.env.NODE_ENV || 'development',
|
|
build: process.env.npm_package_version || 'unknown',
|
|
};
|
|
});
|
|
|
|
// API documentation
|
|
publicRouter.get('/docs', async () => {
|
|
return {
|
|
title: 'FrenoCorp API Gateway',
|
|
version: '1.0.0',
|
|
endpoints: {
|
|
public: [
|
|
{ method: 'GET', path: '/', description: 'Root endpoint' },
|
|
{ method: 'GET', path: '/health', description: 'Health check' },
|
|
{ method: 'GET', path: '/api/v1/info', description: 'API version info' },
|
|
{ method: 'GET', path: '/api/v1/docs', description: 'API documentation' },
|
|
],
|
|
authenticated: [
|
|
{ method: 'GET', path: '/api/v1/auth/user/me', description: 'Get current user' },
|
|
{ method: 'GET', path: '/api/v1/auth/services', description: 'List available services' },
|
|
],
|
|
},
|
|
};
|
|
});
|
|
},
|
|
{ prefix: '/api/v1' }
|
|
);
|
|
|
|
// Service proxy placeholder (for future microservice routing)
|
|
fastify.register(
|
|
async (services) => {
|
|
services.get('/services/user', async (request, reply) => {
|
|
// In production, proxy to actual user service
|
|
return {
|
|
service: 'user-service',
|
|
message: 'User service endpoint',
|
|
timestamp: new Date().toISOString(),
|
|
};
|
|
});
|
|
|
|
services.get('/services/billing', async (request, reply) => {
|
|
// In production, proxy to actual billing service
|
|
return {
|
|
service: 'billing-service',
|
|
message: 'Billing service endpoint',
|
|
timestamp: new Date().toISOString(),
|
|
};
|
|
});
|
|
|
|
services.get('/services/notifications', async (request, reply) => {
|
|
// In production, proxy to actual notification service
|
|
return {
|
|
service: 'notification-service',
|
|
message: 'Notification service endpoint',
|
|
timestamp: new Date().toISOString(),
|
|
};
|
|
});
|
|
},
|
|
{ prefix: '/api/v1/services' }
|
|
);
|
|
|
|
// VoicePrint service routes
|
|
fastify.register(
|
|
async (voiceprintRouter) => {
|
|
await voiceprintRoutes(voiceprintRouter);
|
|
},
|
|
{ prefix: '/voiceprint' }
|
|
);
|
|
|
|
// SpamShield service routes
|
|
fastify.register(
|
|
async (spamshieldRouter) => {
|
|
await spamshieldRoutes(spamshieldRouter);
|
|
},
|
|
{ prefix: '/spamshield' }
|
|
);
|
|
|
|
// DarkWatch service routes
|
|
fastify.register(
|
|
async (darkwatchRouter) => {
|
|
await darkwatchRoutes(darkwatchRouter);
|
|
},
|
|
{ prefix: '/darkwatch' }
|
|
);
|
|
}
|