diff --git a/.editorconfig b/.editorconfig index 603bcd19..32d7eabe 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,7 @@ root = true [Makefile] indent_style = tab -[*.js] +[*.js,*.ts] indent_style = space indent_size = 2 diff --git a/ui/src/client.ts b/ui/src/client.ts new file mode 100644 index 00000000..d7ef2a6b --- /dev/null +++ b/ui/src/client.ts @@ -0,0 +1,47 @@ +import * as client from './client/src'; + + +declare global { + interface Window { + enduro: any; + fgt_sslvpn: any; + } +} + +function apiPath(): string { + const location = window.location; + const path = location.protocol + + '//' + + location.hostname + + (location.port ? ':' + location.port : '') + + location.pathname + + (location.search ? location.search : ''); + + return path.replace(/\/$/, ''); +} + +export let EnduroCollectionClient: client.CollectionApi; + +export function setUpEnduroClient() { + let path = apiPath(); + + // path seems to be wrong when Enduro is deployed behind FortiNet SSLVPN. + // There is some URL rewriting going on that is beyond my understanding. + // This is an attempt to rewrite the URL using their url_rewrite function. + if (typeof window.fgt_sslvpn !== 'undefined') { + path = window.fgt_sslvpn.url_rewrite(path); + } + + const config: client.Configuration = new client.Configuration({basePath: path}); + EnduroCollectionClient = new client.CollectionApi(config); + + // tslint:disable-next-line:no-console + console.log('Enduro client created', path); +} + +window.enduro = { + // As a last resort, user could run window.enduro.reload() from console? + reload: () => { + setUpEnduroClient(); + }, +}; diff --git a/ui/src/components/CollectionDetail.vue b/ui/src/components/CollectionDetail.vue index 2fb794a2..d508cd6a 100644 --- a/ui/src/components/CollectionDetail.vue +++ b/ui/src/components/CollectionDetail.vue @@ -73,7 +73,7 @@