forked from shubhexists/MeetBackend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (52 loc) · 1.79 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require("express");
const connectDb = require("./config/dbConnection");
const responseTime = require('response-time');
const client = require('prom-client');
const errorHandler = require("./middleware/errorHandler");
const dotenv = require("dotenv").config();
const cors = require("cors");
connectDb();
//DONT USE BCRYPT AS WE NEED TO DISPLAY THE PASSWORD IN THE FRONTEND
const app = express();
const port = process.env.PORT || 5000;
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics({ register: client.register});
const reqResTime = new client.Histogram({
name: 'request_response_time',
help: 'Response time in millis',
labelNames: ['method', 'route', 'status_code'],
buckets: [0.1, 5, 15, 50, 100, 500, 1000, 2000, 2500, 3000, 5000]
});
const totalRequests = new client.Counter({
name: 'total_requests',
help: 'Total number of requests',
});
app.use(express.json());
app.use(cors());
app.use(
responseTime((req, res, time) => {
totalRequests.inc();
if (req.url !== '/metrics') {
reqResTime
.labels(req.method, req.url, res.statusCode)
.observe(time);
}
}
));
app.get("/api/url", (req, res) =>
res.json({ url: "wss://livekit.zoomtod.com" }),
);
app.get("/metrics", async (req, res) => {
res.setHeader('Content-Type', client.register.contentType);
const metrics = await client.register.metrics();
res.send(metrics);
});
app.use("/api/auth", require("./routes/authRoutes"));
app.use("/api/livekit", require("./routes/livekitRoutes"));
app.use("/api/owner", require("./routes/ownerRoutes"));
app.use("/api/admin", require("./routes/adminRoutes"));
app.use("/api/user", require("./routes/userRoutes"));
app.use(errorHandler);
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});