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


const app = express();
app.use(express.json());
const port = 3000;

const apiRouter = require('./routes/api.js');
app.use('/api', apiRouter);


app.use(cors());
app.use(express.json());
app.use(express.static(path.join(__dirname, '..')));



// Initialize DB and start server
(async () => {
  try {
    await sequelize.authenticate();
    console.log('DB connection established.');
    await sequelize.sync(); // Only if you want Sequelize to ensure schema matches

    app.listen(port, '0.0.0.0', () =>
      console.log(`Server running at http://0.0.0.0:${port}`)
    );
  } catch (err) {
    console.error('Failed to start:', err);
  }
})();
