-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
93 lines (83 loc) · 3.35 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import express from "express";
import { addToPublisherRegistry, verifyPublisherExistence } from "./handlers/publishers/publisher.js";
import { addToContextsRegistry, verifyContextExistence } from "./handlers/contexts/context.js";
import { registerNewLog, getLogs } from "./handlers/logsHandler/logs.js";
import { ResponseStandardizer } from "./handlers/utilities/responseUtility.js";
const app = express();
const PORT = process.env.PORT || 8080;
app.use(express.json());
app.get("/", function (request, response) {
response.send({
message: "Welcome to Logsmith Monitor!",
version: "logsmith-monitor v0.1.0-alpha"
})
})
// New Publisher Route
app.post("/publisher", function (request, response) {
const newPublisherRequestProfile = request.body;
addToPublisherRegistry(newPublisherRequestProfile, function (PublisherRegistryResponse) {
ResponseStandardizer(PublisherRegistryResponse, function (StatusCode, ResponseBody) {
response.status(StatusCode)
response.send(ResponseBody)
})
});
})
// check publisher
app.get("/:publisher", function (request, response) {
const Publisher = request.params.publisher;
verifyPublisherExistence(Publisher, function (PublisherRegistryResponse) {
ResponseStandardizer(PublisherRegistryResponse, function (StatusCode, ResponseBody) {
response.status(StatusCode)
response.send(ResponseBody)
})
});
})
// New Context Route
app.post("/:publisher/context", function (request, response) {
const Publisher = request.params.publisher;
const newContextRequestProfile = request.body;
addToContextsRegistry(Publisher, newContextRequestProfile, function (ContextRegistryResponse) {
ResponseStandardizer(ContextRegistryResponse, function (StatusCode, ResponseBody) {
response.status(StatusCode)
response.send(ResponseBody)
})
})
})
// check context
app.get("/:publisher/:context", function (request, response) {
const Publisher = request.params.publisher;
const Context = request.params.context;
verifyContextExistence(Publisher, Context, function (PublisherRegistryResponse) {
ResponseStandardizer(PublisherRegistryResponse, function (StatusCode, ResponseBody) {
response.status(StatusCode)
response.send(ResponseBody)
})
});
})
// Publish Log Route
app.post("/:publisher/:context/logs", function (request, response) {
const Publisher = request.params.publisher;
const Context = request.params.context;
const newLog = request.body;
registerNewLog(Publisher, Context, newLog, function (LogRegistryResponse) {
ResponseStandardizer(LogRegistryResponse, function (StatusCode, ResponseBody) {
response.status(StatusCode)
response.send(ResponseBody)
})
})
})
// Get Logs Route
app.get("/:publisher/:context/logs", function (request, response) {
const Publisher = request.params.publisher;
const Context = request.params.context;
getLogs(Publisher, Context, function (LogRegistryResponse) {
ResponseStandardizer(LogRegistryResponse, function (StatusCode, ResponseBody) {
response.status(StatusCode)
response.send(ResponseBody)
})
})
})
// Server Defination
app.listen(PORT, function () {
console.log("Running on http://localhost:" + PORT)
})