-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (52 loc) · 1.77 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
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 flash = require("express-flash");
const logger = require("morgan");
const methodOverride = require("method-override");
const connectDB = require("./config/database");
const mainRoutes = require("./routes/main");
const priceListsRoutes = require("./routes/priceLists");
const portalRoutes = require("./routes/portal");
const documentsRoutes = require("./routes/docs");
const productIDRoutes = require("./routes/productID");
const vueProductIDRoutes = require("./routes/vueProductID");
const jobsRoutes = require("./routes/jobs");
require("dotenv").config({ path: "./config/.env" });
// Passport config
require("./config/passport")(passport);
connectDB().then(() => {
app.listen(process.env.PORT, () => {
console.log(`Server is running on port ${process.env.PORT}.`);
});
});
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(logger("dev"));
//Use forms for put / delete
app.use(methodOverride("_method"));
// Sessions
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
})
);
// Passport middleware
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use("/", mainRoutes);
app.use("/priceLists", priceListsRoutes);
app.use("/portal", portalRoutes);
app.use("/docs", documentsRoutes);
app.use("/productID", productIDRoutes);
app.use("/vueProductID", vueProductIDRoutes);
app.use("/jobs", jobsRoutes);