mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
25 lines
589 B
JavaScript
25 lines
589 B
JavaScript
|
'use strict';
|
||
|
|
||
|
const logger = require('../logger');
|
||
|
const ClientMetrics = require('../client-metrics');
|
||
|
|
||
|
module.exports = function (app) {
|
||
|
const metrics = new ClientMetrics();
|
||
|
|
||
|
app.get('/metrics', (req, res) => {
|
||
|
res.json(metrics.getState());
|
||
|
});
|
||
|
|
||
|
app.post('/metrics', (req, res) => {
|
||
|
// TODO: validate input and reply with http errorcode
|
||
|
try {
|
||
|
const data = JSON.parse(req.body);
|
||
|
metrics.addPayload(data);
|
||
|
} catch (e) {
|
||
|
logger.error('Error recieving metrics', e);
|
||
|
}
|
||
|
|
||
|
res.end();
|
||
|
});
|
||
|
};
|