var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var nunjucks = require('nunjucks')

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

// Configure MongoDb as DDBBB and Mongoose as ODM
var db = require('./config/db');

// Configure Nunjucks with 'view' as template directory
nunjucks.configure('views', {
	autoescape: true,
	express: app
})

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Bootstrap 4 and necessary libraries
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
app.use('/js', express.static(__dirname + '/node_modules/jquery/dist'));
app.use('/js', express.static(__dirname + '/node_modules/popper.js/dist'));
app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js'));

app.use('/', indexRouter);
app.use('/users', usersRouter);

module.exports = app;
