-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
100 lines (86 loc) · 2.52 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
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
98
99
100
var cluster = require("cluster");
if (cluster.isMaster) {
var cpuCount = require("os").cpus().length;
for (var i = 0; i < cpuCount; i += 1) {
cluster.fork();
}
} else {
require("dotenv").config();
var session = require("express-session");
var bodyParser = require("body-parser");
const TasksRouter = require("./controllers/tasks");
const AuthRouter = require("./controllers/auth");
const ProfileRouter = require("./controllers/profile/profile.js");
const ActionRouter = require("./controllers/actions.js");
const RegionRouter = require("./controllers/regions/region.js");
const express = require("express");
const app = express();
var RedisStore = require('connect-mongo')(session);
const mongoose = require("mongoose");
mongoose
.connect(
process.env.MONGO,
{ useNewUrlParser: true }
)
.then(() => console.log("Connected to database!"))
.catch(err => {
console.log(err);
});
app.use(bodyParser.json());
app.use(
session({
store: new RedisStore({
mongooseConnection: mongoose.connection
}),
secret: "keyboarddcat",
resave: true,
saveUninitialized: true,
cookie: { secure: false }
})
);
app.use(express.static("public"));
app.use(function cros(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use("/tasks", TasksRouter);
app.use("/auth", AuthRouter);
app.use("/profile", ProfileRouter);
app.use("/actions", ActionRouter);
app.use("/regions", RegionRouter);
app.get("/", (req, res) => {
if (req.session.userId) {
//Send the ReactJSX admin panel.
res.redirect("/maker");
} else {
//Send Key page
res.sendFile(__dirname + "/views/index.html");
}
});
app.get("/maker/", (req, res) => {
if (req.session.userId) {
res.sendFile(__dirname + "/views/suite/index.html");
}
});
app.get("/maker/*", (req, res) => {
if (req.session.userId) {
res.sendFile(__dirname + "/views/suite/index.html");
}
});
app.get("/health", (req, res) => {
res.json({ running: true });
});
app.get("*", (req, res) => {
if (req.session.userId) {
res.sendFile(__dirname + "/views/suite/index.html");
} else {
res.redirect("/");
}
});
app.listen(80);
console.log("Running", cluster.worker.id);
}