use text/plain on /api/metrics

This commit is contained in:
Danny Coates 2019-02-15 11:59:39 -08:00
parent b30be6e4a2
commit 8eaacfea18
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
4 changed files with 11 additions and 5 deletions

View file

@ -41,13 +41,17 @@ function submitEvents() {
events events
}) })
], ],
{ type: 'application/json' } { type: 'text/plain' } // see http://crbug.com/490015
); );
events.splice(0); events.splice(0);
if (!navigator.sendBeacon) { if (!navigator.sendBeacon) {
return; return;
} }
try {
navigator.sendBeacon('/api/metrics', data); navigator.sendBeacon('/api/metrics', data);
} catch (e) {
console.error(e);
}
} }
async function addEvent(event_type, event_properties) { async function addEvent(event_type, event_properties) {

View file

@ -136,6 +136,7 @@
"dependencies": { "dependencies": {
"@google-cloud/storage": "^2.4.2", "@google-cloud/storage": "^2.4.2",
"aws-sdk": "^2.400.0", "aws-sdk": "^2.400.0",
"body-parser": "^1.18.3",
"choo": "^6.12.1", "choo": "^6.12.1",
"cldr-core": "^34.0.0", "cldr-core": "^34.0.0",
"convict": "^4.4.1", "convict": "^4.4.1",

View file

@ -1,5 +1,5 @@
const crypto = require('crypto'); const crypto = require('crypto');
const express = require('express'); const bodyParser = require('body-parser');
const helmet = require('helmet'); const helmet = require('helmet');
const uaparser = require('ua-parser-js'); const uaparser = require('ua-parser-js');
const storage = require('../storage'); const storage = require('../storage');
@ -69,7 +69,8 @@ module.exports = function(app) {
res.set('Cache-Control', 'no-cache'); res.set('Cache-Control', 'no-cache');
next(); next();
}); });
app.use(express.json()); app.use(bodyParser.json());
app.use(bodyParser.text());
app.get('/', language, pages.index); app.get('/', language, pages.index);
app.get('/oauth', language, pages.blank); app.get('/oauth', language, pages.blank);
app.get('/legal', language, pages.legal); app.get('/legal', language, pages.legal);

View file

@ -2,7 +2,7 @@ const { sendBatch, clientEvent } = require('../amplitude');
module.exports = async function(req, res) { module.exports = async function(req, res) {
try { try {
const data = req.body; const data = JSON.parse(req.body); // see http://crbug.com/490015
const deltaT = Date.now() - data.now; const deltaT = Date.now() - data.now;
const events = data.events.map(e => const events = data.events.map(e =>
clientEvent( clientEvent(