| import express from 'express';
|
| import mongoose from 'mongoose';
|
| import cors from 'cors';
|
| import dotenv from 'dotenv';
|
| import uploadRoutes from './routes/upload.js';
|
| import analysisRoutes from './routes/analysis.js';
|
|
|
| dotenv.config();
|
|
|
| const app = express();
|
| const PORT = process.env.PORT || 5000;
|
|
|
|
|
| app.use(cors({
|
| origin: process.env.CLIENT_URL || 'http://localhost:5173',
|
| credentials: true
|
| }));
|
| app.use(express.json());
|
| app.use(express.urlencoded({ extended: true }));
|
|
|
|
|
| mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/rag-document-analysis')
|
| .then(() => console.log('β
MongoDB connected successfully'))
|
| .catch((err) => console.error('β MongoDB connection error:', err));
|
|
|
|
|
| app.use('/api/upload', uploadRoutes);
|
| app.use('/api/analysis', analysisRoutes);
|
|
|
|
|
| app.get('/api/health', (req, res) => {
|
| res.json({
|
| status: 'OK',
|
| message: 'RAG Document Analysis API is running',
|
| timestamp: new Date().toISOString()
|
| });
|
| });
|
|
|
|
|
| app.use((err, req, res, next) => {
|
| console.error('Error:', err);
|
| res.status(err.status || 500).json({
|
| error: err.message || 'Internal server error',
|
| ...(process.env.NODE_ENV === 'development' && { stack: err.stack })
|
| });
|
| });
|
|
|
|
|
| app.listen(PORT, () => {
|
| console.log(`π Server running on http://localhost:${PORT}`);
|
| console.log(`π Environment: ${process.env.NODE_ENV || 'development'}`);
|
| });
|
|
|