Skip to content

Commit

Permalink
use text/plain on /api/metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Feb 15, 2019
1 parent b30be6e commit 8eaacfe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ function submitEvents() {
events
})
],
{ type: 'application/json' }
{ type: 'text/plain' } // see http://crbug.com/490015
);
events.splice(0);
if (!navigator.sendBeacon) {
return;
}
navigator.sendBeacon('/api/metrics', data);
try {
navigator.sendBeacon('/api/metrics', data);
} catch (e) {
console.error(e);
}
}

async function addEvent(event_type, event_properties) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"dependencies": {
"@google-cloud/storage": "^2.4.2",
"aws-sdk": "^2.400.0",
"body-parser": "^1.18.3",
"choo": "^6.12.1",
"cldr-core": "^34.0.0",
"convict": "^4.4.1",
Expand Down
5 changes: 3 additions & 2 deletions server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const crypto = require('crypto');
const express = require('express');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const uaparser = require('ua-parser-js');
const storage = require('../storage');
Expand Down Expand Up @@ -69,7 +69,8 @@ module.exports = function(app) {
res.set('Cache-Control', 'no-cache');
next();
});
app.use(express.json());
app.use(bodyParser.json());
app.use(bodyParser.text());
app.get('/', language, pages.index);
app.get('/oauth', language, pages.blank);
app.get('/legal', language, pages.legal);
Expand Down
2 changes: 1 addition & 1 deletion server/routes/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { sendBatch, clientEvent } = require('../amplitude');

module.exports = async function(req, res) {
try {
const data = req.body;
const data = JSON.parse(req.body); // see http://crbug.com/490015
const deltaT = Date.now() - data.now;
const events = data.events.map(e =>
clientEvent(
Expand Down

0 comments on commit 8eaacfe

Please sign in to comment.