-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (42 loc) · 1.58 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
// Inicio del código del Backend de EduSys
// Requerimientos para la App.
const express = require('express')
const mongoose = require('mongoose')
require('dotenv').config()
const Admin = require("./src/models/admin.model")
const adminRouter = require('./src/routes/admin.route')
const adminAuthRouter = require('./src/routes/adminAuth.route')
const institutionRouter = require('./src/routes/institution.route')
const alumnoRouter = require('./src/routes/alumno.route')
const notasRouter = require('./src/routes/notas.route')
const { crearSuperAdmin, crearMaterias } = require("./src/common/functions")
const cors = require("cors")
const morgan = require("morgan")
const Materias = require('./src/models/materias.model')
const app = express()
app.use(cors())
const port = 8000
app.use(express.json({ limit: "50mb" }))
if(process.env.NODE_ENV === "development") {
app.use(morgan("dev"))
}
// Rutas para la aplicación
app.use("/admin", adminRouter)
app.use("/auth", adminAuthRouter)
app.use("/inst", institutionRouter)
app.use("/alumno", alumnoRouter)
app.use("/notas", notasRouter)
mongoose.connect(process.env.MONGO_URI).then(() => {
Admin.findOne().then(admins => {
if (admins === null) { crearSuperAdmin() }
})
Materias.findOne().then(materias => {
if (materias === null) { crearMaterias() }
})
console.log("Conectado a la base de datos")
app.listen(port, () => {
console.log(
`La aplicación se está ejecutando en el puerto ${port}`
);
});
}).catch(() => { console.log("Hubo un error en la conexión a la base de datos...")})