forked from SamarthAroraa/Sensus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (81 loc) · 2.42 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const express = require("express");
const app = express();
const cors = require("cors");
const cookieParser = require("cookie-parser");
const expressLayouts = require("express-ejs-layouts");
const db = require("./config/mongoose");
const session = require("express-session");
const passport = require("passport");
const passportLocal = require("./config/passport-local-strategy");
const passportJWT = require("./config/passport-jwt");
const MongoStore = require("connect-mongo")(session);
const env = require("./config/environment");
const partials = require("express-partials");
const sassMiddleware = require("node-sass-middleware");
const flash = require("connect-flash");
const flashMiddleware = require("./config/flash_middleware");
const port = 5000;
const path = require("path");
// app.use(
// sassMiddleware({
// src: path.join(__dirname, env.asset_path, "scss"),
// dest: path.join(__dirname, env.asset_path, "css"),
// debug: true,
// outputStyle: "extended",
// prefix: "/css",
// })
// );
app.use(
express.urlencoded({
extended: true,
})
);
app.use(cookieParser());
app.use(expressLayouts);
app.set("layout extractStyles", true);
app.set("layout extractScripts", true);
app.use(express.static(path.join(__dirname, env.asset_path)));
app.use(partials());
app.use(cors());
app.use(
session({
name: "sensus",
//TO DO change secret before deployment
secret: env.session_cookie_key,
saveUninitialized: false,
resave: true,
require: false,
cookie: {
maxAge: null,
},
store: new MongoStore(
{
mongooseConnection: db,
autoRemove: "disabled",
},
function (err) {
console.log(err || "connect-mogodb ok");
}
),
})
);
app.use(flash());
app.use(flashMiddleware.setFlash);
// Passport middleware
app.use(passport.initialize());
// Passport config
require("./config/passport-jwt")(passport);
app.use(express.static(path.join(__dirname, "client/build")));
app.use("/users", require("./routes/users"));
app.use("/app-utils", require("./routes/utils"));
app.use("/api", require("./routes/api"));
app.use("/forgot-password", require("./routes/forgot_password"));
// app.get("/", function(req, res) {
// res.sendFile(path.join(__dirname, "client", "build", "index.html"));
// });
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
app.listen(port, () => {
console.log(`Server is active on port:${port}`);
});