-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (47 loc) · 1.38 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
'use stric'
//Dependencias usadas
const express = require('express')
const mongoose = require('mongoose')
const bearerToken = require('express-bearer-token')
const cors = require('cors')
const config = require("./config");
const app = express()
const PORT = process.env.PORT || 3000
app.use(express.json())
app.use(cors())
app.use(bearerToken())
// Traemos las rutas necesarias
const usersRoute = require('./routes/users')
const LoginRoute = require('./routes/auth')
const comentsRoute = require('./routes/comments')
const devicesRoute = require('./routes/devices')
const contactRoute = require('./routes/messages')
// Enganchamos la ruta
app.use(usersRoute)
app.use(LoginRoute)
app.use(comentsRoute)
app.use(devicesRoute)
app.use(contactRoute)
app.get("/", (req, res) => {
res.send('Hola mundo')
})
async function conectDatabase() {
let db = mongoose.connections;
try {
await mongoose.connect(config.mongoConfig, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
} catch (err) {
console.log(`
No ha sido posible conectar con la base de datos.
`)
}
}
async function init() {
await conectDatabase();
app.listen(PORT, () => console.log(`Conectado al puerto http://localhost:${PORT}`))
}
init();
module.exports = app;