-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (40 loc) · 1.02 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
const path = require('path')
const express = require('express')
const mongoose = require('mongoose')
const app = express()
require('dotenv').config()
const viewsPath = path.join(__dirname, './')
app.set('views', viewsPath)
app.use(express.static(viewsPath))
/**
* Ler JSON
*/
app.use(
express.urlencoded({
extended: true,
}),
)
app.use(express.json())
/**
* Rota da API
*/
const personRoutes = require('./src/routes/personRoutes')
app.use('/person', personRoutes)
/**
* Rota inicial
*/
app.get('', async(req, res) => {
try{
res.render('index')
}catch(error){
res.status(500).json({error: error})
}
})
/**
* Entregar uma porta
*/
mongoose.connect(`mongodb+srv://${process.env.BD_USER}:${process.env.BD_PASSWORD}@clusterapi.uwe76.mongodb.net/?retryWrites=true&w=majority`)
.then(app.listen(process.env.BD_PORT, process.env.BD_HOST, () => {
console.log(`Connected: http://${process.env.BD_HOST}:${process.env.BD_PORT}`)
})
).catch((error)=> console.log(error))