UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

40 lines (39 loc) 1.32 kB
import express from 'express'; import cors from 'cors'; import path from 'path'; import { fileURLToPath } from 'url'; import { FileService } from './services/fileService.js'; import fileRoutes from './routes/fileRoutes.js'; import llmRoutes from './routes/llm.js'; import chatRoutes from './routes/chat.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); export class Server { constructor() { this.app = express(); this.port = 2668; this.fileService = new FileService(); this.setupMiddleware(); this.setupRoutes(); } setupMiddleware() { this.app.use(cors()); this.app.use(express.json()); this.app.use(express.static(path.join(__dirname, '../public'))); } setupRoutes() { // Mount the routes under /api this.app.use('/api', fileRoutes); this.app.use('/api', llmRoutes); this.app.use('/api', chatRoutes); // Serve index.html for all other routes (SPA fallback) this.app.get('*', (_req, res) => { res.sendFile(path.join(__dirname, '../public/index.html')); }); } start() { this.app.listen(this.port, () => { console.log(`Server running at http://localhost:${this.port}`); }); } }