22 lines
625 B
JavaScript
22 lines
625 B
JavaScript
module.exports = (req, res, next) => {
|
|
const start = performance.now();
|
|
|
|
res.on("finish", () => {
|
|
const duration = performance.now() - start;
|
|
|
|
fetch("http://metrics:4005/push", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
type: "rest",
|
|
path: req.originalUrl,
|
|
method: req.method,
|
|
status: res.statusCode,
|
|
time: duration,
|
|
timestamp: Date.now()
|
|
})
|
|
}).catch(err => console.error(err));
|
|
});
|
|
|
|
next();
|
|
}; |