52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
/**
|
|
* Express API Server
|
|
* @author Descomplicar® | @link descomplicar.pt | @copyright 2026
|
|
*/
|
|
import 'dotenv/config'
|
|
import express from 'express'
|
|
import cors from 'cors'
|
|
import dashboardRouter from './routes/dashboard.js'
|
|
import monitorRouter from './routes/monitor.js'
|
|
import diagnosticRouter from './routes/diagnostic.js'
|
|
import hetznerRouter from './routes/hetzner.js'
|
|
import wpMonitorRouter from './routes/wp-monitor.js'
|
|
|
|
const app = express()
|
|
const PORT = process.env.API_PORT || 3001
|
|
|
|
// Middleware
|
|
app.use(cors({
|
|
origin: process.env.FRONTEND_URL || 'http://localhost:5173',
|
|
credentials: true
|
|
}))
|
|
app.use(express.json())
|
|
|
|
// Health check
|
|
app.get('/api/health', (_req, res) => {
|
|
res.json({ status: 'ok', timestamp: new Date().toISOString() })
|
|
})
|
|
|
|
// Routes
|
|
app.use('/api/dashboard', dashboardRouter)
|
|
app.use('/api/monitor', monitorRouter)
|
|
app.use('/api/diagnostic', diagnosticRouter)
|
|
app.use('/api/hetzner', hetznerRouter)
|
|
app.use('/api/wp-monitor', wpMonitorRouter)
|
|
|
|
// Error handling
|
|
app.use((err: any, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
|
|
console.error('Server error:', err)
|
|
res.status(500).json({ error: 'Internal server error' })
|
|
})
|
|
|
|
// Start server
|
|
app.listen(PORT, () => {
|
|
console.log('='.repeat(50))
|
|
console.log(`🚀 API Server running on http://localhost:${PORT}`)
|
|
console.log(`📊 Dashboard: http://localhost:${PORT}/api/dashboard`)
|
|
console.log(`🔍 Monitor: http://localhost:${PORT}/api/monitor`)
|
|
console.log(`🔧 Diagnostic: http://localhost:${PORT}/api/diagnostic`)
|
|
console.log(`☁️ Hetzner: http://localhost:${PORT}/api/hetzner`)
|
|
console.log('='.repeat(50))
|
|
})
|