-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
82 lines (66 loc) · 1.95 KB
/
server.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express=require("express")
const app=express()
const mongoose=require("mongoose")
const passport=require("passport")
const session=require("express-session")
const MongoStore = require("connect-mongo")(session);
const methodOverride=require("method-override")
const flash=require("express-flash")
const connectDB=require("./config/database")
const mainRoutes=require("./routes/main")
const issuesRoutes=require("./routes/issues")
const notesRoutes=require("./routes/notes")
const taxisRoutes=require("./routes/taxis")
const wakeUpCallsRoutes=require("./routes/wakeUpCalls")
const usersRoutes=require("./routes/users")
const moment=require("moment")
//dotenv config
require("dotenv").config({path: "./config/config.env"})
//mongoose settings
mongoose.set('strictQuery', false);
// Passport config
require("./config/passport")(passport);
//Connect To Database
connectDB();
//Using EJS for views
app.set("view engine", "ejs");
//moment setup
app.locals.moment = moment;
//Static Folder
app.use(express.static("public"));
//Body Parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Method Override
app.use(methodOverride(function (req,res){
if(req.body && typeof req.body === 'object' && '_method' in req.body){
let method=req.body._method
delete req.body._method
return method
}
}))
//Sessions setup
app.use(
session({
secret: "keyboard cat",
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
})
);
// Passport middleware
app.use(passport.initialize());
app.use(passport.session());
//Flash setup
app.use(flash())
//Setup Routes
app.use("/", mainRoutes)
app.use("/issues",issuesRoutes)
app.use("/notes",notesRoutes)
app.use("/taxis",taxisRoutes)
app.use("/wakeUpCalls",wakeUpCallsRoutes)
app.use("/users",usersRoutes)
//Server Running
app.listen(process.env.PORT, () => {
console.log(console.log(`Server is running!`));
});