-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
47 lines (39 loc) · 968 Bytes
/
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
require('dotenv').config()
const cors = require('cors')
const express = require('express')
const mongoose = require('mongoose')
const mongoDBenv = process.env.DATABASE_URL
const port = process.env.PORT
const app = express()
mongoose.connect(mongoDBenv)
const database = mongoose.connection
database.on('error', (e) => {
console.log(e)
})
database.once('connected', () => {
console.log('Conectado a MongoDB')
})
app.use(
cors({
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
optionsSuccessStatus: 204,
})
)
app.use(express.json())
app.use(express.text())
app.use(express.urlencoded({ extended: false }))
app.get('/', function (req, res) {
respuesta = {
error: false,
codigo: 200,
mensaje: 'Servidor Activo',
}
res.send(respuesta)
})
app.use('/', require('./routes/filmsRoute'))
app.use('/', require('./routes/charactersRoute'))
app.listen(port, () => {
console.log(`Servidor a la escucha en ${port}`)
})