-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
53 lines (44 loc) · 1.45 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
const express = require('express')
const mongoose = require('mongoose')
const MongoStore = require('connect-mongo')
const passport = require('passport')
const session = require('express-session')
const methodOverride = require("method-override");
const logger = require('morgan')
const flash = require('express-flash')
const mainRoutes = require('./routes/mainRoutes')
const postRoutes = require('./routes/postRoutes')
const cors = require('cors')
require('dotenv').config({path: './config/.env'})
require("./config/passport")(passport);
// connect to mongo DB
const connectDB = require('./config/database')
const clientPromise = connectDB()
.then(conn => conn.connection.getClient())
const app = express()
// app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(express.json({limit: '50mb'}))
app.use(express.urlencoded({limit: '50mb', extended: true}))
app.use(logger('dev'))
app.use(cors())
// Sessions
app.use(
session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
store: MongoStore.create({ clientPromise }),
})
);
// Passport middleware
app.use(passport.initialize())
app.use(passport.session())
//Use forms for put / delete
app.use(methodOverride("_method"));
app.use(flash())
app.use('/', mainRoutes)
app.use('/post', postRoutes);
app.listen(process.env.PORT, ()=>{
console.log('Server is running, you better catch it!', `It's running on ${process.env.PORT}`)
})