diff --git a/ui/public/config.json b/ui/public/config.json index 4c9be76b13f..6c134087101 100644 --- a/ui/public/config.json +++ b/ui/public/config.json @@ -1,5 +1,12 @@ { "apiBase": "/client/api", + "servers": [ + { + "name": "Local-Server", + "apiHost": "", + "apiBase": "/client/api" + } + ], "docBase": "http://docs.cloudstack.apache.org/en/latest", "appTitle": "CloudStack", "footer": "Licensed under the Apache License, Version 2.0.", @@ -48,5 +55,6 @@ }, "plugins": [], "basicZoneEnabled": true, + "multipleServer": false, "docHelpMappings": {} } diff --git a/ui/src/components/header/UserMenu.vue b/ui/src/components/header/UserMenu.vue index 33335c6efd1..33f4bc33b00 100644 --- a/ui/src/components/header/UserMenu.vue +++ b/ui/src/components/header/UserMenu.vue @@ -20,6 +20,10 @@ + @@ -59,9 +63,11 @@ diff --git a/ui/src/main.js b/ui/src/main.js index 9fbae3e0acd..dce669d6065 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -37,7 +37,12 @@ Vue.use(toLocaleDatePlugin) fetch('config.json').then(response => response.json()).then(config => { Vue.prototype.$config = config - Vue.axios.defaults.baseURL = config.apiBase + let basUrl = config.apiBase + if (config.multipleServer) { + basUrl = (config.servers[0].apiHost || '') + config.servers[0].apiBase + } + + Vue.axios.defaults.baseURL = basUrl loadLanguageAsync().then(() => { new Vue({ diff --git a/ui/src/permission.js b/ui/src/permission.js index 8e975118611..1b6c468afa0 100644 --- a/ui/src/permission.js +++ b/ui/src/permission.js @@ -26,7 +26,7 @@ import 'nprogress/nprogress.css' // progress bar style import message from 'ant-design-vue/es/message' import notification from 'ant-design-vue/es/notification' import { setDocumentTitle } from '@/utils/domUtil' -import { ACCESS_TOKEN, APIS } from '@/store/mutation-types' +import { ACCESS_TOKEN, APIS, SERVER_MANAGER } from '@/store/mutation-types' NProgress.configure({ showSpinner: false }) // NProgress Configuration @@ -39,6 +39,20 @@ router.beforeEach((to, from, next) => { const title = i18n.t(to.meta.title) + ' - ' + Vue.prototype.$config.appTitle setDocumentTitle(title) } + + if (Vue.prototype.$config.multipleServer) { + const servers = Vue.prototype.$config.servers + const serverStorage = Vue.ls.get(SERVER_MANAGER) + let apiFullPath = '' + if (serverStorage) { + apiFullPath = (serverStorage.apiHost || '') + serverStorage.apiBase + } + const serverFilter = servers.filter(ser => (ser.apiHost || '') + ser.apiBase === apiFullPath) + const server = serverFilter[0] || servers[0] + Vue.axios.defaults.baseURL = (server.apiHost || '') + server.apiBase + store.dispatch('SetServer', server) + } + const validLogin = Vue.ls.get(ACCESS_TOKEN) || Cookies.get('userid') || Cookies.get('userid', { path: '/client' }) if (validLogin) { if (to.path === '/user/login') { diff --git a/ui/src/store/getters.js b/ui/src/store/getters.js index ed9ab4036fa..f694362f095 100644 --- a/ui/src/store/getters.js +++ b/ui/src/store/getters.js @@ -36,6 +36,7 @@ const getters = { zones: state => state.user.zones, timezoneoffset: state => state.user.timezoneoffset, usebrowsertimezone: state => state.user.usebrowsertimezone, + server: state => state.app.server, domainStore: state => state.user.domainStore } diff --git a/ui/src/store/modules/app.js b/ui/src/store/modules/app.js index a03fc63b2ef..e512c42f372 100644 --- a/ui/src/store/modules/app.js +++ b/ui/src/store/modules/app.js @@ -27,7 +27,8 @@ import { DEFAULT_FIXED_HEADER_HIDDEN, DEFAULT_CONTENT_WIDTH_TYPE, DEFAULT_MULTI_TAB, - USE_BROWSER_TIMEZONE + USE_BROWSER_TIMEZONE, + SERVER_MANAGER } from '@/store/mutation-types' const app = { @@ -44,7 +45,8 @@ const app = { color: null, inverted: true, multiTab: true, - metrics: false + metrics: false, + server: '' }, mutations: { SET_SIDEBAR_TYPE: (state, type) => { @@ -100,6 +102,10 @@ const app = { SET_USE_BROWSER_TIMEZONE: (state, bool) => { Vue.ls.set(USE_BROWSER_TIMEZONE, bool) state.usebrowsertimezone = bool + }, + SET_SERVER: (state, server) => { + Vue.ls.set(SERVER_MANAGER, server) + state.server = server } }, actions: { @@ -147,6 +153,9 @@ const app = { }, SetUseBrowserTimezone ({ commit }, bool) { commit('SET_USE_BROWSER_TIMEZONE', bool) + }, + SetServer ({ commit }, server) { + commit('SET_SERVER', server) } } } diff --git a/ui/src/store/mutation-types.js b/ui/src/store/mutation-types.js index 948f9388b79..7adc857b845 100644 --- a/ui/src/store/mutation-types.js +++ b/ui/src/store/mutation-types.js @@ -32,6 +32,7 @@ export const ZONES = 'ZONES' export const HEADER_NOTICES = 'HEADER_NOTICES' export const TIMEZONE_OFFSET = 'TIMEZONE_OFFSET' export const USE_BROWSER_TIMEZONE = 'USE_BROWSER_TIMEZONE' +export const SERVER_MANAGER = 'SERVER_MANAGER' export const DOMAIN_STORE = 'DOMAIN_STORE' export const CONTENT_WIDTH_TYPE = { diff --git a/ui/src/views/auth/Login.vue b/ui/src/views/auth/Login.vue index 42c713721c7..db5ff67b0e5 100644 --- a/ui/src/views/auth/Login.vue +++ b/ui/src/views/auth/Login.vue @@ -35,6 +35,23 @@ {{ $t('label.login.portal') }} + + + + + {{ item.name }} + + + {{ $t('label.login.single.signon') }} + + + + + {{ item.name }} + + + @@ -110,8 +144,11 @@