import express from 'express';
import dotenv from 'dotenv';
import session from 'express-session';
import cookieParser from 'cookie-parser';
import path from 'path';

import ApiRouter from './routers/api.js';
import UserRouter from './routers/user.js';

const app = express();

dotenv.config({path: ".env"});

app.use(session({
    secret: process.env.SECRET,
    resave: true,
    saveUninitialized: false,
    cookie: { maxAge: 1000 * 60 * 60 * 24 }
}));
app.use(express.static(path.join('./public')));
app.use(express.urlencoded({extended: false}));
app.use(express.json());
app.use(cookieParser());

app.set('view engine', 'pug');

app.use('/api', ApiRouter);
app.use('/', UserRouter);

app.listen(process.env.PORT, () => {
    console.log("App has been started!");
});