const express = require('express');
const path = require('path');
require('dotenv').config();

const app = express();
const PORT = process.env.PORT || 3000;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));

// Importa y registra rutas solo UNA vez
const authRoutes = require('./routes/auth');
const routineRoutes = require('./routes/routines');
const userRoutes = require('./routes/users');

app.use('/auth', authRoutes);
app.use('/api/rutinas', routineRoutes);
app.use('/api/users', userRoutes);
app.use('/catalog', express.static(path.join(__dirname, 'catalog')));
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));

app.listen(PORT, () => {
  console.log(`Servidor corriendo en http://localhost:${PORT}`);
});
