Skip to content

Commit

Permalink
Fix: Initialize mapsUrl in cloud native (#5868)
Browse files Browse the repository at this point in the history
  • Loading branch information
alasarr committed Jun 28, 2021
1 parent 3a2c584 commit 33c1309
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion modules/carto/src/api/maps-cloud-native-client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Maps API Client for Carto Cloud Native
*/
import {getDefaultCredentials} from '../config';
import {getDefaultCredentials, buildMapsUrlFromBase} from '../config';
import {API_VERSIONS, encodeParameter, FORMATS, MAP_TYPES} from './maps-api-common';
import {log} from '@deck.gl/core';

Expand Down Expand Up @@ -118,6 +118,10 @@ export async function getData({type, source, connection, credentials, format}) {
log.assert(localCreds.accessToken, 'Must define an accessToken');
log.assert(localCreds.mapsUrl, 'mapsUrl cannot be undefined');

if (!localCreds.mapsUrl) {
localCreds.mapsUrl = buildMapsUrlFromBase(localCreds.apiBaseUrl);
}

const metadata = await mapInstantiation({type, source, connection, credentials: localCreds});
let url;
let mapFormat;
Expand Down
16 changes: 11 additions & 5 deletions modules/carto/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ export function setDefaultCredentials(opts) {
);
}

let apiBaseUrl = opts.apiBaseUrl || defaultCloudNativeCredentials.apiBaseUrl;
if (!apiBaseUrl.endsWith('/')) {
apiBaseUrl += '/';
}
opts.mapsUrl = opts.mapsUrl || `${apiBaseUrl}v3/maps`;
const apiBaseUrl = opts.apiBaseUrl || defaultCloudNativeCredentials.apiBaseUrl;
opts.mapsUrl = opts.mapsUrl || buildMapsUrlFromBase(apiBaseUrl);
credentials = {
apiVersion,
...defaultCloudNativeCredentials,
Expand All @@ -67,3 +64,12 @@ export function setDefaultCredentials(opts) {
export function getDefaultCredentials() {
return credentials;
}

export function buildMapsUrlFromBase(apiBaseUrl) {
let suffix = '/v3/maps';
if (apiBaseUrl.endsWith('/')) {
suffix = suffix.substring(1);
}

return `${apiBaseUrl}${suffix}`;
}

0 comments on commit 33c1309

Please sign in to comment.