import express from 'express';
import config from 'config';
import * as path from 'path';
import * as Indice from './routes/index';
import * as Login from './routes/login';
import bodyParser from 'body-parser';
import expressSession from 'express-session';

enum OpcConfig {
        PUERTO = 'puerto'
}
let app = express();
let puerto = 3000;
if (config.has(OpcConfig.PUERTO)) {
        puerto = config.get(OpcConfig.PUERTO);
} else {
        console.log(`puerto no encontrado, usando default ${puerto}`);
}

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.use(expressSession(
	{
		secret: 'teclado',
		resave: false,
		saveUninitialized: true
	}
));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));
app.use('/', Indice.router);
app.use('/', Login.router);
app.use(express.static(path.join(__dirname, 'resources')));

app.listen(puerto,() => {
        console.log(`escuchando en el puerto ${puerto}`);
});
