FRE-4533: Merge apps/{api,web,mobile} and shared-db into ShieldAI repo
Merge FrenoCorp apps into ShieldAI packages/: - packages/api: merged routes (notifications), middleware (auth, rate-limit, error, logging), config, services (darkwatch, spamshield, voiceprint), tests - packages/web: new SolidJS web app stub - packages/mobile: new SolidJS mobile app stub - packages/shared-db: new Prisma DB package (separate from existing packages/db) - pnpm-workspace.yaml: restored (apps/* removed, already covered by packages/*) Next: reconcile packages/shared-db with packages/db, and fix server.ts correlationRoutes import
This commit is contained in:
55
packages/api/src/config/api.config.ts
Normal file
55
packages/api/src/config/api.config.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// Environment variables
|
||||
const envSchema = z.object({
|
||||
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
||||
PORT: z.string().transform(Number).default(3000),
|
||||
HOST: z.string().default('0.0.0.0'),
|
||||
API_RATE_LIMIT_WINDOW: z.string().transform(Number).default(60000), // 1 minute
|
||||
API_RATE_LIMIT_MAX_REQUESTS: z.string().transform(Number).default(100),
|
||||
CORS_ORIGIN: z.string().default('http://localhost:5173'),
|
||||
});
|
||||
|
||||
export const apiEnv = envSchema.parse({
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
PORT: process.env.PORT,
|
||||
HOST: process.env.HOST,
|
||||
API_RATE_LIMIT_WINDOW: process.env.API_RATE_LIMIT_WINDOW,
|
||||
API_RATE_LIMIT_MAX_REQUESTS: process.env.API_RATE_LIMIT_MAX_REQUESTS,
|
||||
CORS_ORIGIN: process.env.CORS_ORIGIN,
|
||||
});
|
||||
|
||||
// Rate limit configuration by tier
|
||||
export const rateLimitConfig = {
|
||||
basic: {
|
||||
windowMs: 60000, // 1 minute
|
||||
maxRequests: 100,
|
||||
},
|
||||
plus: {
|
||||
windowMs: 60000,
|
||||
maxRequests: 500,
|
||||
},
|
||||
premium: {
|
||||
windowMs: 60000,
|
||||
maxRequests: 2000,
|
||||
},
|
||||
};
|
||||
|
||||
// API versioning configuration
|
||||
export const apiVersioning = {
|
||||
defaultVersion: '1',
|
||||
headerName: 'X-API-Version',
|
||||
queryParam: 'api-version',
|
||||
};
|
||||
|
||||
// Logging configuration
|
||||
export const loggingConfig = {
|
||||
level: apiEnv.NODE_ENV === 'production' ? 'info' : 'debug',
|
||||
transport: apiEnv.NODE_ENV === 'development' ? {
|
||||
target: 'pino-pretty',
|
||||
options: {
|
||||
colorize: true,
|
||||
translateTime: true,
|
||||
},
|
||||
} : undefined,
|
||||
};
|
||||
18
packages/api/src/config/redis.ts
Normal file
18
packages/api/src/config/redis.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Redis } from 'ioredis';
|
||||
|
||||
const redisHost = process.env.REDIS_HOST || 'localhost';
|
||||
const redisPort = parseInt(process.env.REDIS_PORT || '6379', 10);
|
||||
|
||||
export const redis = new Redis({
|
||||
host: redisHost,
|
||||
port: redisPort,
|
||||
retryStrategy: (times: number) => Math.min(times * 50, 2000),
|
||||
lazyConnect: true,
|
||||
});
|
||||
|
||||
export async function getRedisConnection(): Promise<Redis> {
|
||||
if (redis.status === 'wait' || redis.status === 'connecting') {
|
||||
await redis.connect();
|
||||
}
|
||||
return redis;
|
||||
}
|
||||
Reference in New Issue
Block a user