-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
44 lines (31 loc) · 1020 Bytes
/
test.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
const express = require("express");
const { createServer } = require("http");
const { register } = require("prom-client");
const {
graceful,
instrumentConnections,
createLoggingMiddleware,
createErrorMiddleware,
createMetricsMiddleware,
registerMetrics,
Router,
} = require("./dist");
registerMetrics(register);
const app = express();
app.use(createLoggingMiddleware(console));
app.use(createMetricsMiddleware());
app.get("/metrics", async (req, res) => res.send(await register.metrics()));
const router = new Router();
router.get("/", ({ req, res }) => res.send("done"));
router.get("/var/:myvar", ({ req, res, params }) => res.json(params.myvar));
router.get("/error", ({ req, res }) => {
console.log(req.socket.address());
throw new Error("Errorzz!!!");
});
app.use(router.createHandler());
app.use(createErrorMiddleware(console));
const server = createServer(app);
instrumentConnections(server);
const { shutdown } = graceful(server);
server.listen(3000);
setTimeout(shutdown, 60000);