-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (39 loc) · 1.35 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
const express = require("express");
const path = require("path");
const cookieSession = require("cookie-session");
const FeedbackService = require("./services/FeedbackService");
const SpeakerService = require("./services/SpeakerService");
const feedbackService = new FeedbackService("./data/feedback.json");
const speakersService = new SpeakerService("./data/speakers.json");
const routes = require("./routes");
// eslint-disable-next-line no-param-reassign, no-underscore-dangle
// const __dirname = dirname(fileURLToPath(import.meta.url));
// const __dirname = fileURLToPath(import.meta.url);
// const _dirname = path.dirname(_filename);
const app = express();
const port = 3000;
app.set("trust proxy", 1);
app.use(
cookieSession({
name: "session",
keys: ["ddfer43erw", "445rresdfgw21"],
})
);
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "./views"));
app.locals.siteName = "NEx-SITE";
app.use(express.static(path.join(__dirname, "./static")));
app.use(async (request, response, next) => {
try {
const names = await speakersService.getNames();
response.locals.speakerNames = names;
return next();
} catch (e) {
return next(e);
}
});
app.use("/", routes({ feedbackService, speakersService }));
app.listen(port, () => {
// eslint-disable-next-line
console.log(`Express Server Listening on port: ${port}`);
});