app.ts 864 B

123456789101112131415161718192021222324
  1. import express from 'express';
  2. import cors from 'cors';
  3. import type { Express } from 'express';
  4. import { getStringEnv } from '../../../shared/config/env.js';
  5. import { apiKeyAuth } from '../../../shared/http/auth.middleware.js';
  6. import { errorHandler } from '../../../shared/http/error-handler.js';
  7. import { notFoundHandler } from '../../../shared/http/not-found.middleware.js';
  8. import { mobileChatApiRouter } from './routes/chat.routes.js';
  9. export function createMobileChatApp(): Express {
  10. const app = express();
  11. const corsOrigin = getStringEnv('CORS_ORIGIN') ?? 'http://localhost:4200';
  12. app.use(cors({ origin: corsOrigin.split(',').map((o) => o.trim()), credentials: true }));
  13. app.use(express.json({ limit: '1mb' }));
  14. app.use(apiKeyAuth);
  15. app.use('/api', mobileChatApiRouter);
  16. app.use(notFoundHandler);
  17. app.use(errorHandler);
  18. return app;
  19. }