-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
console.log('Entorno de: ', process.env.NODE_ENV);
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line global-require
require('dotenv').config();
}
const cors = require('cors');
const morgan = require('morgan');
const express = require('express');
const config = require('./config');
const database = require('./connection/connectDB');
const authMiddleware = require('./middleware/auth');
const authRouter = require('./routes/auth');
const usersRouter = require('./routes/users');
const candidatesRouter = require('./routes/candidate');
const requestRouter = require('./routes/request');
const agregaciones = require('./examples/pAgregaciones');
// A. Crear el Servidor.
const app = express();
// B. Conexion a la bd.
database();
// C. Middleware - Cors - Permite acceso al API de otros dominios.
app.use(cors());
// D. Middleware - Permite ver data enviada del navegador por CLI.
app.use(morgan('dev'));
// F. Middleware - Parse application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// G. authMiddleware
app.use(authMiddleware(config.secret));
/* // registrar rutas
routes(app, (err) => {
if (err) throw err;
app.listen(config.port, () => {
console.info(`App listening on port ${config.port}`);
});
}); */
// H. Middleware - Importar rutas.
app.use(authRouter);
app.use(usersRouter);
app.use(candidatesRouter);
app.use(requestRouter);
app.use(agregaciones);
app.listen(config.port, () => {
console.log(`App listen port ${config.port}`);
});