-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
58 lines (45 loc) · 1.44 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
56
57
58
// hacer el import de express tradicional
// const express = require('express');
// hacer el nuevo import
import serverless from 'serverless-http';
import Express from 'express';
import Cors from 'cors';
import dotenv from 'dotenv';
import { conectarBD } from './db/db.js';
import jwt from 'express-jwt';
import jwks from 'jwks-rsa';
import rutasVehiculo from './views/vehiculos/rutas.js';
import rutasUsuario from './views/usuarios/rutas.js';
import rutasVenta from './views/ventas/rutas.js';
import autorizacionEstadoUsuario from './middleware/autorizacionEstadoUsuario.js';
dotenv.config({ path: './.env' });
const port = process.env.PORT || 5000;
const app = Express();
app.use(Express.json());
app.use(Cors());
var jwtCheck = jwt({
secret: jwks.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: 'https://misiontic-concesionario.us.auth0.com/.well-known/jwks.json',
}),
audience: 'api-autenticacion-concesionario-mintic',
issuer: 'https://misiontic-concesionario.us.auth0.com/',
algorithms: ['RS256'],
});
// 4 y 5: enviarle el token a auth0 para que devuelva si es valido o no
app.use(jwtCheck);
app.use(autorizacionEstadoUsuario);
app.use(rutasVehiculo);
app.use(rutasUsuario);
app.use(rutasVenta);
const main = () => {
return app.listen(port, () => {
console.log(`escuchando puerto ${port}`);
});
};
const index = {
handler: serverless(conectarBD(main)),
};
export default index;