-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (35 loc) · 1.21 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
const path = require("path");
const express = require("express");
const session = require("express-session");
const { COMPUTERS_PATH, PERIPHERALS_PATH, USERS_PATH } = require("./config");
const indexRouter = require("./routes/index");
const computersRouter = require("./routes/computers");
const peripheralsRouter = require("./routes/peripherals");
const usersRouter = require("./routes/users");
const server = express();
server.enable("trust proxy");
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
server.use(express.static(path.join(__dirname, "public")));
const expressSession = {
secret: "hamiltj2",
cookie: {},
resave: false,
saveUninitialized: true,
};
server.use(session(expressSession));
server.use("/", indexRouter);
server.use(COMPUTERS_PATH, computersRouter);
server.use(PERIPHERALS_PATH, peripheralsRouter);
server.use(USERS_PATH, usersRouter);
server.use((err, req, res, next) => {
if (err.name === "UnauthorizedError") {
res.status(401).end();
}
});
// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
server.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
module.exports = server;