-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.js
67 lines (56 loc) · 1.6 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
require("dotenv").config();
const express = require("express");
const path = require("path");
const app = express();
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const MongoDBURI = process.env.MONGO_URI
mongoose.connect(MongoDBURI, {
useUnifiedTopology: true,
useNewUrlParser: true,
});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", () => {});
app.use(
session({
secret: "LHDIDH$#%@$^#$^oq$#@%FSDFDSF@$ihvVSFIVHISHI41$#@^#%&#$$@#$JBVVLJSV",
resave: true,
saveUninitialized: false,
store: new MongoStore({
mongooseConnection: db,
}),
cookie: {
maxAge: 1 * 24 * 60 * 60 * 1000
}
})
);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(__dirname + "/views"));
const index = require("./routes/index");
const admin = require("./routes/admin");
const task = require("./routes/task");
app.use("/", index);
app.use("/admin", admin);
app.use("/task", task);
app.use((req, res, next) => {
res.render("error", {
code: "404",
msg: "Lost in space?",
icon: "fa-solid fa-meteor",
username: []
})
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send(err.message);
});
// listen on port 3000
app.listen(process.env.PORT || 3000, () => {
console.log("Express app listening on port 3000");
});