const express = require('express');
const cors = require('cors');
require('dotenv').config();
const sequelize = require('./config/database');

const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Sinkronisasi DB (Otomatis buat table kalau blm ada)
sequelize.sync({ alter: true }).then(() => {
    console.log('Database terhubung & tersinkronisasi');
    const PORT = process.env.PORT || 5000;
    app.listen(PORT, () => console.log(`Server jalan di port ${PORT}`));
}).catch(err => console.error('Error DB:', err));

// Routes
app.use('/api/auth', require('./routes/auth'));
app.use('/api/licenses', require('./routes/licenses'));
app.use('/api/ea', require('./routes/ea_api'));
