-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (51 loc) · 1.39 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
58
59
60
61
62
const express = require('express')
require('dotenv').config();
const cors = require('cors');
const bodyParser = require('body-parser');
const flash = require('express-flash')
const session = require('express-session')
const methodOverride = require('method-override')
const passport = require('passport')
const mongoConnect = require('./databaseAuth/mongoConnect');
const routes = require('./routes/routes');
// Create the express app
const app = express()
const port = process.env.PORT || 5000
mongoConnect();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.set('view-engine','ejs');
app.use(flash())
app.use(session({
secret:process.env.SESSION_SECRET,
resave:false,
saveUninitialized:false
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(methodOverride('_method'))
// Routes and middleware
// app.use(/* ... */)
// app.get(/* ... */)
app.use('/api',routes)
app.get('/',(req,res) => {
res.render('home.ejs')
})
// Error handlers
app.use(function fourOhFourHandler (req, res) {
res.status(404).send()
})
app.use(function fiveHundredHandler (err, req, res, next) {
console.error(err)
res.status(500).send()
})
// Start server
app.listen(port, function (err) {
if (err) {
return console.error(err)
}
console.log(`Server Started at :${port}`)
})