-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (33 loc) · 1.16 KB
/
app.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
import express, { request } from 'express'
import morgan from 'morgan'
import cors from 'cors'
import path from 'path'
const mongoose = require('mongoose');
const app = express()
// DB connection
// Local connection
// const uri = 'mongodb://localhost:27017/mevn'
// Mongo altas cluster connection
const uri = 'mongodb+srv://MEVN:[email protected]/mevn?retryWrites=true&w=majority'
const options = {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true}
mongoose.connect(uri, options).then(
() => { console.log('connect to mongodb') },
err => { err }
);
// Middleware
app.use(morgan('tiny'))
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
// Endpoints
app.use('/api', require('./routes/note'))
app.use('/api', require('./routes/user'))
app.use('/api/login', require('./routes/login'))
// Middleware para Vue.js router modo history
const history = require('connect-history-api-fallback')
app.use(history());
app.use(express.static(path.join(__dirname, 'public')))
app.set('port', process.env.PORT || 3000)
app.listen(app.get('port'), () => {
console.log('App listening on port: '+ app.get('port'))
});