import express from 'express';
import cors from 'cors';
import router from './routes/router.js';
import { getAppPort, getConfig } from './config.js';

const app = express();

app.use(cors());
app.use(express.json());

// Handle multipart in motor controller separately
app.use('/audio', express.json());
app.use('/motor', express.json());
app.use('/commands', express.json());

app.use(router);

app.get('/health', (_req, res) => {
  const settings = getConfig();
  res.json({ status: 'ok', settings });
});

app.listen(getAppPort(), () => {
  console.log(`QuiBot backend listening on port ${getAppPort()}`);
});
