const express = require('express');
const bodyParser = require('body-parser');
const loginRouter = require('./routers/login');
const menuRouter = require('./routers/mainMenu');
const path = require('path');
const cookieParser = require('cookie-parser');

const checkSession = require('./middlewares/checkSession');

const app = express()

app.set('serverProcess', null);

app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(express.static(path.join(__dirname, 'public', 'html')));
app.use('/css', express.static(path.join(__dirname, 'public', 'css')));
app.use('/js', express.static(path.join(__dirname, 'public', 'js')));
app.use('/images', express.static(path.join(__dirname, 'public', 'assets')));

app.use(checkSession);

// Mount login and menu routers
app.use('/login', loginRouter);
app.use('/', menuRouter);

// Start the server
const PORT = process.env.PORT || 80;
app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});
