Skip to content

Commit c19bc09

Browse files
Added proxyApi
1 parent 63d7e1e commit c19bc09

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/services/api.js

+18
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,21 @@ export async function getTcM2mToken() {
290290
const token = await m2m.getMachineToken(TC_M2M.CLIENT_ID, TC_M2M.CLIENT_SECRET);
291291
return token;
292292
}
293+
294+
/**
295+
* Call API via proxy
296+
*
297+
* @param {String} url to API endpoint
298+
*/
299+
export async function proxyApi(endpoint) {
300+
let domain = '';
301+
if (isomorphy.isServerSide()) {
302+
domain = `http://${config.ENV.HOST || 'localhost'}:${config.ENV.PORT || 3000}`;
303+
}
304+
const url = `${domain}/community-app-assets/api${endpoint}`;
305+
let res = await fetch(url);
306+
if (!res.ok) throw new Error(res.statusText);
307+
res = (await res.json());
308+
if (res.message) throw new Error(res.message);
309+
return res;
310+
}

0 commit comments

Comments
 (0)