/**
 * @file index.js
 * @author Radim Buráň (xburan03@stud.fit.vutbr.cz)
 */

const express = require('express');
const userRoutes = require('./routes/usersRoutes');
const recordsRoutes = require('./routes/recordsRoutes');
const devicesRoutes = require('./routes/devicesRoutes');
const presetDataRoutes = require('./routes/presetsRoutes');
const commentsRoutes = require('./routes/commentsRoutes');
const authRoutes = require('./routes/authRoutes');
const cors = require('cors');
const cookieParser = require("cookie-parser");
require('dotenv').config();
require('./services/mqttService');

const app = express();

app.use(cors({
    origin: process.env.CLIENT_URL,
    credentials: true
}));
app.use(express.json());
app.use(cookieParser(process.env.SECRET_COOKIE));
app.use('/', authRoutes);
app.use('/users', userRoutes);
app.use('/records', recordsRoutes);
app.use('/devices', devicesRoutes);
app.use('/presets', presetDataRoutes);
app.use('/comments', commentsRoutes);

const apiPort = process.env.API_PORT;

app.listen(apiPort, () => {
    console.log(`Backend API listening at http://localhost:${apiPort}`)
})
