Skip to content

Commit

Permalink
[Maps] Always initialize routes on server-startup (#84806)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Dec 2, 2020
1 parent a5dd5b6 commit 65cbe4c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
24 changes: 10 additions & 14 deletions x-pack/plugins/maps/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,23 @@ export class MapsPlugin implements Plugin {
return;
}

let routesInitialized = false;
let isEnterprisePlus = false;
let lastLicenseId: string | undefined;
const emsSettings = new EMSSettings(mapsLegacyConfig, () => isEnterprisePlus);
licensing.license$.subscribe((license: ILicense) => {
const basic = license.check(APP_ID, 'basic');

const enterprise = license.check(APP_ID, 'enterprise');
isEnterprisePlus = enterprise.state === 'valid';

if (basic.state === 'valid' && !routesInitialized) {
routesInitialized = true;
initRoutes(
core.http.createRouter(),
license.uid,
emsSettings,
this.kibanaVersion,
this._logger
);
}
lastLicenseId = license.uid;
});

initRoutes(
core.http.createRouter(),
() => lastLicenseId,
emsSettings,
this.kibanaVersion,
this._logger
);

this._initHomeData(home, core.http.basePath.prepend, emsSettings);

features.registerKibanaFeature({
Expand Down
40 changes: 23 additions & 17 deletions x-pack/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,32 @@ const EMPTY_EMS_CLIENT = {
addQueryParams() {},
};

export function initRoutes(router, licenseUid, emsSettings, kbnVersion, logger) {
export function initRoutes(router, getLicenseId, emsSettings, kbnVersion, logger) {
let emsClient;

if (emsSettings.isIncludeElasticMapsService()) {
emsClient = new EMSClient({
language: i18n.getLocale(),
appVersion: kbnVersion,
appName: EMS_APP_NAME,
fileApiUrl: emsSettings.getEMSFileApiUrl(),
tileApiUrl: emsSettings.getEMSTileApiUrl(),
landingPageUrl: emsSettings.getEMSLandingPageUrl(),
fetchFunction: fetch,
});
emsClient.addQueryParams({ license: licenseUid });
} else {
emsClient = EMPTY_EMS_CLIENT;
}
let lastLicenseId;

function getEMSClient() {
return emsSettings.isEMSEnabled() ? emsClient : EMPTY_EMS_CLIENT;
const currentLicenseId = getLicenseId();
if (emsClient && emsSettings.isEMSEnabled() && lastLicenseId === currentLicenseId) {
return emsClient;
}

lastLicenseId = currentLicenseId;
if (emsSettings.isIncludeElasticMapsService()) {
emsClient = new EMSClient({
language: i18n.getLocale(),
appVersion: kbnVersion,
appName: EMS_APP_NAME,
fileApiUrl: emsSettings.getEMSFileApiUrl(),
tileApiUrl: emsSettings.getEMSTileApiUrl(),
landingPageUrl: emsSettings.getEMSLandingPageUrl(),
fetchFunction: fetch,
});
emsClient.addQueryParams({ license: currentLicenseId });
return emsClient;
} else {
return EMPTY_EMS_CLIENT;
}
}

router.get(
Expand Down

0 comments on commit 65cbe4c

Please sign in to comment.