-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
98 lines (82 loc) · 2.65 KB
/
index.js
File metadata and controls
98 lines (82 loc) · 2.65 KB
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
import express from "express";
import mongoose from "mongoose";
import bodyParser from "body-parser";
import fileUpload from "express-fileupload";
import expressSession from "express-session";
import compression from "compression";
const app = express();
app.disable("x-powered-by");
// Database
mongoose.connect("mongodb://127.0.0.1/AdjaraGroup");
app.set("view engine", "ejs");
// Middleware
app.use(express.static("public"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(fileUpload());
app.use(
expressSession({
secret: "aggpbicmac",
resave: true,
saveUninitialized: true,
})
);
app.use(compression());
global.loggedIn = null;
app.use("*", (req, res, next) => {
global.loggedIn = req.session.userId;
next();
});
import navigationMiddleware from "./middleware/navigation.js";
app.use(navigationMiddleware);
// Routes
// User pages
import homeCtrl from "./controllers/home.js";
import homeOld from "./controllers/homeOld.js";
import companyCtrl from "./controllers/company.js";
import hotelsCtrl from "./controllers/hotels.js";
import restaurantsCtrl from "./controllers/restaurants.js";
import sitemapCtrl from "./controllers/sitemap.js";
import privacyCtrl from "./controllers/privacy.js";
import newsroomCtrl from "./controllers/newsroom.js";
import newsroomArchiveCtrl from "./controllers/newsroomArchive.js";
import articleCtrl from "./controllers/article.js";
import careersCtrl from "./controllers/careers.js";
import jobCtrl from "./controllers/job.js";
app.get("/", homeCtrl);
app.get("/homeOld", homeOld);
app.get("/company", companyCtrl);
app.get("/hotels", hotelsCtrl);
app.get("/restaurants", restaurantsCtrl);
app.get("/sitemap", sitemapCtrl);
app.get("/privacy", privacyCtrl);
app.get("/newsroom", newsroomCtrl);
app.get("/newsroom/archive", newsroomArchiveCtrl);
app.get("/newsroom/:id", articleCtrl);
app.get("/careers", careersCtrl);
app.get("/careers/job", jobCtrl);
import articleAPICtrl from "./controllers/API/articleAPI.js";
import careerAPICtrl from "./controllers/API/careersAPI.js";
app.use(articleAPICtrl);
app.use(careerAPICtrl);
// Admin pages
import userCtrl from "./controllers/user.js";
app.use(userCtrl);
// 404
app.use(async (req, res, next) => {
res.status(404);
res.render("404");
next();
});
// 500
app.use(async (err, req, res, next) => {
res.render("500", {
message: err.message,
error: err,
});
next();
});
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server successfully running on http://localhost:${PORT}; Press Ctrl + c to terminate.`);
});