-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (46 loc) · 1.55 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const express = require('express')
const colors = require('colors')
const dotenv = require('dotenv')
const morgan = require('morgan')
const connectDb = require('./config/connectDb')
const methodOverride = require("method-override")
const passport = require("passport")
const mongoose = require("mongoose")
const session = require("express-session")
const MongoStore = require("connect-mongo")
dotenv.config({path: './config/.env'});
connectDb();
require("./config/passport-config")(passport);
const app = express();
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(
methodOverride(function (req, res) {
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
// look in urlencoded POST bodies and delete it
let method = req.body._method
delete req.body._method
return method
}
})
)
if(process.env.NODE_ENV === "development")
{
app.use(morgan('dev'));
}
app.use(express.static(__dirname+"/public"));
app.set("view engine", "ejs" );
app.use(session({
secret:process.env.SESSION_SECRET,
resave:false,
saveUninitialized:false,
store: MongoStore.create({mongoUrl: process.env.MONGO_URI})
}))
app.use(passport.initialize());
app.use(passport.session());
app.use("/", require("./routes/index"));
app.use("/auth", require("./routes/auth"));
app.use("/stories", require("./routes/stories"));
const PORT= process.env.PORT || 5000;
app.listen(PORT, ()=>
console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.yellow.bold));