mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-20 02:41:25 +02:00
✨ feat: add mana-api-gateway for monetizing core services
Implement custom NestJS API Gateway for mana-search, mana-stt, and mana-tts: - API Key management with CRUD operations and key regeneration - Redis-based sliding window rate limiting - Credit-based billing with tier support (free, pro, enterprise) - Usage tracking with daily aggregates - Proxy services to backend microservices - Prometheus metrics endpoint - JWT auth for management API, API key auth for public API Database schema uses separate `api_gateway` schema in shared manacore DB.
This commit is contained in:
parent
fbd315eac0
commit
6f1b2654f1
48 changed files with 2507 additions and 0 deletions
56
services/mana-api-gateway/src/proxy/proxy.module.ts
Normal file
56
services/mana-api-gateway/src/proxy/proxy.module.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { MulterModule } from '@nestjs/platform-express';
|
||||
import { memoryStorage } from 'multer';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import Redis from 'ioredis';
|
||||
import { ProxyController } from './proxy.controller';
|
||||
import { SearchProxyService, SttProxyService, TtsProxyService } from './services';
|
||||
import { ApiKeysModule } from '../api-keys/api-keys.module';
|
||||
import { UsageModule } from '../usage/usage.module';
|
||||
import { CreditsModule } from '../credits/credits.module';
|
||||
import { ApiKeyGuard } from '../guards/api-key.guard';
|
||||
import { RateLimitGuard, REDIS_CLIENT } from '../guards/rate-limit.guard';
|
||||
import { CreditsGuard } from '../guards/credits.guard';
|
||||
import { UsageTrackingInterceptor } from '../common/interceptors/usage-tracking.interceptor';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MulterModule.register({
|
||||
storage: memoryStorage(),
|
||||
limits: {
|
||||
fileSize: 100 * 1024 * 1024, // 100MB max file size
|
||||
},
|
||||
}),
|
||||
ApiKeysModule,
|
||||
UsageModule,
|
||||
CreditsModule,
|
||||
],
|
||||
controllers: [ProxyController],
|
||||
providers: [
|
||||
SearchProxyService,
|
||||
SttProxyService,
|
||||
TtsProxyService,
|
||||
ApiKeyGuard,
|
||||
RateLimitGuard,
|
||||
CreditsGuard,
|
||||
UsageTrackingInterceptor,
|
||||
{
|
||||
provide: REDIS_CLIENT,
|
||||
useFactory: (configService: ConfigService) => {
|
||||
const host = configService.get<string>('redis.host') || 'localhost';
|
||||
const port = configService.get<number>('redis.port') || 6379;
|
||||
const password = configService.get<string>('redis.password');
|
||||
|
||||
return new Redis({
|
||||
host,
|
||||
port,
|
||||
password: password || undefined,
|
||||
keyPrefix: configService.get<string>('redis.keyPrefix') || 'api-gateway:',
|
||||
});
|
||||
},
|
||||
inject: [ConfigService],
|
||||
},
|
||||
],
|
||||
exports: [REDIS_CLIENT],
|
||||
})
|
||||
export class ProxyModule {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue