From 889fae5a37def5d76d5f2ea2be43edeab25bc12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Mon, 19 Sep 2022 09:24:20 +0000 Subject: [PATCH] OVDashboardPlugin.api_version --- ui/src/plugins/ovdashboard.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ui/src/plugins/ovdashboard.ts b/ui/src/plugins/ovdashboard.ts index 7b10886..1c39b63 100644 --- a/ui/src/plugins/ovdashboard.ts +++ b/ui/src/plugins/ovdashboard.ts @@ -3,8 +3,9 @@ import Vue from 'vue'; export class OVDashboardPlugin { private axios: AxiosInstance; + private api_version: string; - public constructor() { + public constructor(api_version: string) { // Full config: https://github.com/axios/axios#request-config // axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || ''; // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; @@ -17,6 +18,7 @@ export class OVDashboardPlugin { }; this.axios = axios.create(config); + this.api_version = api_version; } public install(vue: typeof Vue) { @@ -25,23 +27,20 @@ export class OVDashboardPlugin { private get api_baseurl(): string { if (process.env.NODE_ENV === "production") { - return "//" + window.location.host + "/api/v1"; + return `//${window.location.host}/api`; - } else { - if (process.env.NODE_ENV !== "development") { - console.warn("Unexpected NODE_ENV value"); - } - - return "//" + window.location.hostname + ":8000/api/v1"; + } else if (process.env.NODE_ENV !== "development") { + console.warn("Unexpected NODE_ENV value"); } + + return `//${window.location.hostname}:8000/api`; } public api_url(endpoint?: string): string { if (endpoint === undefined) - return this.api_baseurl; + return `${this.api_baseurl}/${this.api_version}`; - else - return this.api_baseurl + "/" + endpoint; + return `${this.api_baseurl}/${this.api_version}/${endpoint}`; } private fail(name: string): (reason: unknown) => void { @@ -141,4 +140,4 @@ export class OVDashboardPlugin { } } -export default new OVDashboardPlugin(); +export default new OVDashboardPlugin("v1");