drop.chapril.org-firefoxsend/server/routes/metrics.js
Danny Coates b5ef1785ab
replaced fxa-geodb with load balancer header
Co-authored-by: timvisee <tim@visee.me>
2020-10-16 15:51:28 +02:00

25 lines
585 B
JavaScript

const { sendBatch, clientEvent } = require('../amplitude');
module.exports = async function(req, res) {
try {
const data = JSON.parse(req.body); // see http://crbug.com/490015
const deltaT = Date.now() - data.now;
const events = data.events.map(e =>
clientEvent(
e,
req.ua,
data.lang,
data.session_id + deltaT,
deltaT,
data.platform,
req.geo.country,
req.geo.state
)
);
const status = await sendBatch(events);
res.sendStatus(status);
} catch (e) {
res.sendStatus(500);
}
};