Sets up the basic project structure for OmniSupport AI, including: - Vite build tool configuration. - React and necessary dependencies. - TypeScript configuration. - Basic HTML and root component setup. - Initial type definitions and mock data for core entities like tickets, agents, and queues. - A README with setup instructions. - A .gitignore file for common build artifacts and development files.
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
|
|
import express from 'express';
|
|
import cors from 'cors';
|
|
import { checkConnection, query } from './db.js';
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// Health Check & DB Init trigger
|
|
app.get('/api/health', async (req, res) => {
|
|
const dbStatus = await checkConnection();
|
|
res.json({
|
|
status: 'ok',
|
|
database: dbStatus ? 'connected' : 'disconnected',
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
});
|
|
|
|
// --- API ENDPOINTS EXAMPLES (To replace Mock Data) ---
|
|
|
|
// Get All Agents
|
|
app.get('/api/agents', async (req, res) => {
|
|
try {
|
|
const agents = await query('SELECT * FROM agents');
|
|
res.json(agents);
|
|
} catch (e) {
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
// Get Tickets
|
|
app.get('/api/tickets', async (req, res) => {
|
|
try {
|
|
const tickets = await query('SELECT * FROM tickets ORDER BY created_at DESC');
|
|
res.json(tickets);
|
|
} catch (e) {
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🚀 Backend Server running on port ${PORT}`);
|
|
checkConnection(); // Initial check
|
|
});
|