events: Correctly proxy mixpanel events

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2018-11-20 17:07:46 +00:00
parent a0841b18f6
commit f48e85095b
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
4 changed files with 11 additions and 4 deletions

View File

@ -65,7 +65,7 @@
"lodash": "^4.16.3",
"log-timestamp": "^0.1.2",
"memoizee": "^0.4.1",
"mixpanel": "0.0.20",
"mixpanel": "https://github.com/balena-io-modules/mixpanel-node",
"mkdirp": "^0.5.1",
"mocha": "^5.1.1",
"mochainon": "^2.0.0",

View File

@ -1,6 +1,7 @@
import * as Bluebird from 'bluebird';
import { Transaction } from 'knex';
import * as _ from 'lodash';
import { URL } from 'url';
import Config = require('../config');
import supervisorVersion = require('../lib/supervisor-version');
@ -107,7 +108,8 @@ export function createProviderFunctions(
mixpanelHost: {
get: () => {
return config.get('apiEndpoint').then(apiEndpoint => {
return `${apiEndpoint}/mixpanel`;
const url = new URL(apiEndpoint as string);
return { host: url.host, path: '/mixpanel' };
});
},
},

View File

@ -12,7 +12,7 @@ export type EventTrackProperties = Dictionary<any>;
interface InitArgs {
uuid: string;
offlineMode: boolean;
mixpanelHost: string;
mixpanelHost: { host: string; path: string };
mixpanelToken: string;
}
@ -55,7 +55,10 @@ export class EventTracker {
if (offlineMode) {
return;
}
this.client = Mixpanel.init(mixpanelToken, { host: mixpanelHost });
this.client = Mixpanel.init(mixpanelToken, {
host: mixpanelHost.host,
path: mixpanelHost.path,
});
});
}

View File

@ -27,6 +27,7 @@ describe 'EventTracker', ->
promise = @eventTrackerOffline.init({
offlineMode: true
uuid: 'foobar'
mixpanelHost: { host: '', path: '' }
})
expect(promise).to.be.fulfilled
.then =>
@ -40,6 +41,7 @@ describe 'EventTracker', ->
promise = @eventTracker.init({
mixpanelToken: 'someToken'
uuid: 'barbaz'
mixpanelHost: { host: '', path: '' }
})
expect(promise).to.be.fulfilled
.then =>