-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (45 loc) · 1.34 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
const express = require("express");
const app = express();
const path = require("path");
const bodyParser = require("body-parser");
const PORT = process.env.PORT || 8080;
const {
AuthRouter,
MainRouter,
UserRouter,
OverlayRouter,
} = require("./routes");
const db = require("./db");
//Cookie and Session
const cookieParser = require("cookie-parser");
const session = require("express-session");
app.use(
session({
secret: "awesome",
resave: true,
saveUninitialized: true,
})
);
const passport = require("passport");
require("./config/passport")(passport); //passport configuration
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
// render server side template
app.set("view engine", "ejs");
app.use(express.static(path.resolve(__dirname, "./client/build")));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
db.on("error", console.error.bind(console, "MongoDB connection error:"));
app.use("/", MainRouter);
app.use("/api", UserRouter);
app.use("/api", OverlayRouter);
app.use("/auth", AuthRouter);
app.get("*", function (request, response) {
response.sendFile(path.resolve(__dirname, "./client/build", "index.html"));
});
app.listen(PORT, () => {
console.log(`App listening on PORT: ${PORT}`);
});