|
| 1 | +import BodyParser from "body-parser"; |
1 | 2 | import Compression from "compression"; |
2 | 3 | import Cors from "cors"; |
3 | 4 | import Express, { Router, static as Statics } from "express"; |
4 | | -import BodyParser from "body-parser"; |
5 | 5 | import Helmet, { frameguard } from "helmet"; |
| 6 | +import Mongoose from "mongoose"; |
6 | 7 | import Path from "path"; |
7 | 8 |
|
8 | 9 | import ApiRouter from "./router"; |
@@ -43,20 +44,36 @@ Server.use(ApiRouter(Router)); |
43 | 44 | // ====================== ESTABLECIENDO CONEXIÓN ====================== // |
44 | 45 |
|
45 | 46 | /** |
46 | | - * Inicializacion del servidor. |
47 | | - * |
48 | | - * @param {Number} PORT Puerto por el que estara escuhcando el server. |
49 | | - * @param {Function} Callback Permite identificar el estado del proceso. |
50 | | - * |
51 | | - * return void. |
| 47 | + * Conexión a MongoDB Atlas. |
52 | 48 | */ |
53 | | -Server.listen(APP_PORT, (error) => { |
54 | | - Helpers.messages("Iniciando el Servidor", "i"); |
55 | | - if (error) { |
56 | | - Helpers.messages("Problemas al inicar el servidor", "e"); |
57 | | - console.log(error); // eslint-disable-line |
58 | | - process.exit(1); |
59 | | - } else { |
60 | | - Helpers.messages(`🚀 Servidor listo en el puerto ${APP_PORT}`, "s"); |
| 49 | +Mongoose.connect( |
| 50 | + process.env.ODBC, |
| 51 | + process.env.CONFIG, |
| 52 | + (mongoError) => { |
| 53 | + if (mongoError) { |
| 54 | + Helpers.messages("Problemas de conexión a MongoDB Atlas", "e"); |
| 55 | + console.log(mongoError); |
| 56 | + process.exit(1); |
| 57 | + } |
| 58 | + /** |
| 59 | + * Inicializacion del servidor. |
| 60 | + * |
| 61 | + * @param {Number} PORT Puerto por el que estara escuhcando el server. |
| 62 | + * @param {Function} Callback Permite identificar el estado del proceso. |
| 63 | + * |
| 64 | + * return void. |
| 65 | + */ |
| 66 | + Server.listen(APP_PORT, (error) => { |
| 67 | + Helpers.messages("Iniciando el Servidor", "i"); |
| 68 | + Helpers.messages("🛰 Conexión establecida con MongoDB Altas", "s"); |
| 69 | + if (error) { |
| 70 | + Helpers.messages("Problemas al inicar el servidor", "e"); |
| 71 | + console.log(error); // eslint-disable-line |
| 72 | + process.exit(1); |
| 73 | + } else { |
| 74 | + Helpers.messages(`🚀 Servidor listo en el puerto ${APP_PORT}`, "s"); |
| 75 | + } |
| 76 | + }); |
61 | 77 | } |
62 | | -}); |
| 78 | +); |
| 79 | + |
0 commit comments