-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (66 loc) · 2.23 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
const configs = require("./configurations/app.config.js");
const express = require("express");
const helmet = require("helmet");
const compression = require("express-compression");
const bodyParse = require("body-parser");
const verify = require("./utilities/firebase.js").verify;
var morgan = require("morgan");
//MIDDLEWARES
const app = express();
//ADDED FOR LOGGING
// app.use(morgan("combined"));
app.use(helmet());
app.use(compression());
app.use(bodyParse.json());
app.use(verify);
//ROUTES
const twitterRoutes = require("./routes/twitterRoutes");
const youTubeRoutes = require("./routes/youtubeRoutes.js");
const twitchRoutes = require("./routes/twitchRoutes.js");
const authRoutes = require("./routes/authRoutes.js");
const streamRoutes = require("./routes/streamRoutes.js");
const elasticsearchRoutes = require("./routes/elasticsearchRoutes.js");
const howItworksRoutes = require("./routes/howItWorkRoutes.js");
const quizRoutes = require("./routes/quizRoutes.js");
//HEADERS
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"OPTIONS, GET, POST, PUT, PATCH, DELETE"
);
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
next();
});
//ROUTER
app.use("/api/twitter", twitterRoutes);
app.use("/api/youtube", youTubeRoutes);
app.use("/api/twitch", twitchRoutes);
app.use("/api/auth", authRoutes);
app.use("/api/stream", streamRoutes);
app.use("/api/elasticsearch", elasticsearchRoutes);
app.use("/api/howitworks", howItworksRoutes);
app.use("/api/quiz", quizRoutes);
app.use("/api/checker", (req, res, next) => {
try {
res.status(200).json({ msg: "ONS BE is working well!" });
} catch (err) {
next(err);
}
});
app.use("/", (req, res, next) => {
const status = 400;
const message = "Nothing to see here, sorry";
res.status(status).json({ status: status, message: message });
});
app.use((error, req, res, next) => {
console.log("[ons]", error);
const status = error.statusCode || 500;
const message = error.message;
res.status(status).json({ status: status, message: message });
});
app.listen(configs.appDefaultPort, () => {
console.log(
`${configs.appName} is listening to port: ${configs.appDefaultPort}`
);
});