import express from 'express';
import cors from 'cors';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import authRoutes from './routes/auth.js';
import gastosRoutes from './routes/gastos.js';
import articulosRoutes from './routes/articulos.js';
import './db/init.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express();
const PORT = process.env.PORT ?? 3001;
app.use(cors());
app.use(express.json());
app.use('/uploads', express.static(path.join(__dirname, '../uploads')));
app.use('/api/auth', authRoutes);
app.use('/api/gastos', gastosRoutes);
app.use('/api/articulos', articulosRoutes);
app.get('/api/health', (_req, res) => {
    res.json({ estado: 'ok' });
});
app.use((err, _req, res, _next) => {
    console.error(err);
    res.status(500).json({ error: err.message || 'Error interno del servidor' });
});
app.listen(PORT, () => {
    console.log(`API escuchando en http://localhost:${PORT}`);
});
