Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agility/content-fetch",
"version": "2.0.9",
"version": "2.0.10",
"description": "JS/TS library for the Agility Fetch API",
"repository": {
"type": "git",
Expand Down
29 changes: 17 additions & 12 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,29 @@ const defaultConfig: Config = {

function buildBaseUrl(guid: string) {

let baseUrlSuffixes = {
const baseUrlSuffixes: { [key: string]: string } = {
u: '',
c: '-ca',
e: '-eu',
a: '-aus',
d: '-dev'
d: '-dev',
us2: '-usa2'
};

// Match for -us2, -c, -u, -e, -a, -d at the end of the guid
const match = guid.match(/-(us2|[ucead])$/);

if (match) {
const env = match[1];
if (baseUrlSuffixes.hasOwnProperty(env)) {
const url = `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`;
return url;
}
}

let suffix = guid.substr(guid.length - 2, 2);
let env = suffix.substr(1);
// New format of guid
if (suffix.startsWith('-') && baseUrlSuffixes.hasOwnProperty(env)) {
return `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`
}
else {
//use default url
return `https://${guid}-api.agilitycms.cloud`;
}
// use default url
const legacyUrl = `https://${guid}-api.agilitycms.cloud`;
return legacyUrl;
}

function validateConfigParams(configParams: Config) {
Expand Down
11 changes: 11 additions & 0 deletions test/getApi.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ describe('getApi:', function () {
done();
});

it('should return an api client with new stackpath baseUrl based on us2', function (done) {
const baseUrl = 'https://api-usa2.aglty.io/someguid-us2';
const api = agilityFetch.getApi({
guid: 'someguid-us2',
apiKey: 'some-access-token',
baseUrl: null
});
expect(api.config.baseUrl).toBe(baseUrl);
done();
});

it('should return an api client with new stackpath baseUrl based on dev', function (done) {
const baseUrl = 'https://api-dev.aglty.io/some-guid-d';
const api = agilityFetch.getApi({
Expand Down