mongodb
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -50,7 +50,8 @@ services:
|
||||
- wallabicher-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3001/api/stats"]
|
||||
# Usar endpoint /health que no requiere autenticación
|
||||
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3001/api/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
@@ -18,7 +18,7 @@ COPY middlewares/ ./middlewares/
|
||||
COPY routes/ ./routes/
|
||||
COPY services/ ./services/
|
||||
COPY utils/ ./utils/
|
||||
COPY workers.json ./workers.json
|
||||
COPY ../workers.json ./workers.json
|
||||
|
||||
# Exponer puerto
|
||||
EXPOSE 3001
|
||||
|
||||
@@ -6,6 +6,31 @@ import { broadcast } from '../services/websocket.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Health check (no requiere autenticación)
|
||||
router.get('/health', async (req, res) => {
|
||||
try {
|
||||
// Verificar que MongoDB está disponible (opcional, no falla si no está)
|
||||
const db = getDB();
|
||||
const mongodbStatus = db ? 'connected' : 'unavailable';
|
||||
|
||||
res.json({
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
mongodb: mongodbStatus,
|
||||
service: 'wallamonitor-backend'
|
||||
});
|
||||
} catch (error) {
|
||||
// Incluso si hay un error, el servidor está funcionando, así que retornamos ok
|
||||
res.json({
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
mongodb: 'error',
|
||||
service: 'wallamonitor-backend',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Obtener estadísticas (requiere autenticación obligatoria)
|
||||
router.get('/stats', basicAuthMiddleware, async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user