'Use strict'

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
const path = require('path');

//cargar Rutas
var usuario_rutas = require('./routes/usuario');
var correo_rutas = require('./routes/correo');
var ubicacion_rutas = require('./routes/ubicacion');
var permisos_rutas = require('./routes/permiso');
var horario_rutas = require('./routes/horario');
var asistencia_rutas = require('./routes/asistencia');
var documento_rutas = require('./routes/documento');
var evaluacion_rutas = require('./routes/evaluacion');
var cv_reporte_rutas = require('./routes/cv-reporte');
var alimentacion_rutas = require('./routes/alimentacion');
var local_rutas = require('./routes/local');
var notificacion_rutas = require('./routes/notificacion');
var matrices_rutas = require('./routes/matrices');

var cargo_rutas = require('./routes/cargo');
var usuarioServicio_rutas = require('./routes/servicio/usuarioServicio');

app.use(bodyParser.urlencoded({ extended: true }));
//app.use(bodyParser.json({ limit: '1000mb' }));
app.use(bodyParser.json()); //convertir a json als peticiones

//configurar cabeceras http
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Method');
  res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
  res.header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');

  next();
});

// rutas base
app.use('/api', usuario_rutas);
app.use('/api', correo_rutas);
app.use('/api', ubicacion_rutas);
app.use('/api', permisos_rutas);
app.use('/api', asistencia_rutas);
app.use('/api', documento_rutas);
app.use('/api', cv_reporte_rutas);
app.use('/api', evaluacion_rutas);
app.use('/api', alimentacion_rutas);
app.use('/api', horario_rutas);
app.use('/api', local_rutas);
app.use('/api', notificacion_rutas);
app.use('/api', matrices_rutas);
app.use('/api', cargo_rutas);
// servicio
app.use('/api/servicio', usuarioServicio_rutas);



// ESTO ES EN PRODUCCION

app.use('/uploads/fotos', express.static(path.resolve('uploads/fotos')));
app.use('/uploads/evidenciaPermisos', express.static(path.resolve('uploads/evidenciaPermisos')));
app.use('/uploads/CI', express.static(path.resolve('uploads/CI')));
app.use('/uploads/cargasFamiliares', express.static(path.resolve('uploads/cargasFamiliares')));
app.use('/uploads/contratos', express.static(path.resolve('uploads/contratos')));
app.use('/uploads/capacitaciones', express.static(path.resolve('uploads/capacitaciones')));
app.use('/uploads/experienciaLaboral', express.static(path.resolve('uploads/experienciaLaboral')));
app.use('/uploads/documentos', express.static(path.resolve('uploads/documentos')));
app.use('/uploads/hse', express.static(path.resolve('uploads/hse')));
app.use('/uploads/evaluaciones', express.static(path.resolve('uploads/evaluaciones')));
// app.use('/uploads/img-reporte',express.static(path.resolve('uploads/img-reporte')));

// app.use('/uploads/reportes',express.static(path.resolve('uploads/productos')));
// app.use('/uploads/avisos',express.static(path.resolve('uploads/avisos')));
// app.use('/uploads/categorias',express.static(path.resolve('uploads/categorias')));
// app.use('/uploads/juego',express.static(path.resolve('uploads/juego')));

module.exports = app; // hace referencia a la variable de express
