Skip to content

Commit a2810eb

Browse files
authored
Merge pull request #121 from agility/adding-us2-region
Adding US2 region to the Fetch SDK
2 parents 66619a1 + cef16a7 commit a2810eb

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agility/content-fetch",
3-
"version": "2.0.9",
3+
"version": "2.0.10",
44
"description": "JS/TS library for the Agility Fetch API",
55
"repository": {
66
"type": "git",

src/api-client.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,29 @@ const defaultConfig: Config = {
6060

6161
function buildBaseUrl(guid: string) {
6262

63-
let baseUrlSuffixes = {
63+
const baseUrlSuffixes: { [key: string]: string } = {
6464
u: '',
6565
c: '-ca',
6666
e: '-eu',
6767
a: '-aus',
68-
d: '-dev'
68+
d: '-dev',
69+
us2: '-usa2'
70+
};
71+
72+
// Match for -us2, -c, -u, -e, -a, -d at the end of the guid
73+
const match = guid.match(/-(us2|[ucead])$/);
74+
75+
if (match) {
76+
const env = match[1];
77+
if (baseUrlSuffixes.hasOwnProperty(env)) {
78+
const url = `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`;
79+
return url;
80+
}
6981
}
7082

71-
let suffix = guid.substr(guid.length - 2, 2);
72-
let env = suffix.substr(1);
73-
// New format of guid
74-
if (suffix.startsWith('-') && baseUrlSuffixes.hasOwnProperty(env)) {
75-
return `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`
76-
}
77-
else {
78-
//use default url
79-
return `https://${guid}-api.agilitycms.cloud`;
80-
}
83+
// use default url
84+
const legacyUrl = `https://${guid}-api.agilitycms.cloud`;
85+
return legacyUrl;
8186
}
8287

8388
function validateConfigParams(configParams: Config) {

test/getApi.tests.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ describe('getApi:', function () {
100100
done();
101101
});
102102

103+
it('should return an api client with new stackpath baseUrl based on us2', function (done) {
104+
const baseUrl = 'https://api-usa2.aglty.io/someguid-us2';
105+
const api = agilityFetch.getApi({
106+
guid: 'someguid-us2',
107+
apiKey: 'some-access-token',
108+
baseUrl: null
109+
});
110+
expect(api.config.baseUrl).toBe(baseUrl);
111+
done();
112+
});
113+
103114
it('should return an api client with new stackpath baseUrl based on dev', function (done) {
104115
const baseUrl = 'https://api-dev.aglty.io/some-guid-d';
105116
const api = agilityFetch.getApi({

0 commit comments

Comments
 (0)