File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -290,3 +290,21 @@ export async function getTcM2mToken() {
290
290
const token = await m2m . getMachineToken ( TC_M2M . CLIENT_ID , TC_M2M . CLIENT_SECRET ) ;
291
291
return token ;
292
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
+ }
You can’t perform that action at this time.
0 commit comments