We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 63d7e1e commit c19bc09Copy full SHA for c19bc09
src/services/api.js
@@ -290,3 +290,21 @@ export async function getTcM2mToken() {
290
const token = await m2m.getMachineToken(TC_M2M.CLIENT_ID, TC_M2M.CLIENT_SECRET);
291
return token;
292
}
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