From 76390c4959adac606c2026dd91d1ad3aa4ee2f4e Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Tue, 24 Nov 2020 17:26:02 +0500 Subject: [PATCH] fix: web_host option handing --- api/router.go | 12 +++++++++--- web2/public/index.html | 3 ++- web2/src/main.js | 3 +++ web2/src/router/index.js | 1 - web2/src/socket.js | 4 ++-- web2/vue.config.js | 8 ++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/api/router.go b/api/router.go index da051d154..0dbdde066 100644 --- a/api/router.go +++ b/api/router.go @@ -55,9 +55,11 @@ func Route() *mux.Router { r.NotFoundHandler = http.HandlerFunc(servePublic) webPath := "/" - if util.WebHostURL != nil && util.WebHostURL.Hostname() != "0.0.0.0" { - r.Host(util.WebHostURL.Hostname()) + if util.WebHostURL != nil { webPath = util.WebHostURL.Path + if !strings.HasSuffix(webPath, "/") { + webPath += "/" + } } r.Use(mux.CORSMethodMiddleware(r)) @@ -281,9 +283,13 @@ func servePublic(w http.ResponseWriter, r *http.Request) { // replace base path if util.WebHostURL != nil && path == htmlPrefix+"/index.html" { + baseURL := util.WebHostURL.String() + if !strings.HasSuffix(baseURL, "/") { + baseURL += "/" + } res = []byte(strings.Replace(string(res), "", - "", + "", 1)) } diff --git a/web2/public/index.html b/web2/public/index.html index 3bbf8244b..7ca645be2 100644 --- a/web2/public/index.html +++ b/web2/public/index.html @@ -1,10 +1,11 @@ + - + Ansible Semaphore diff --git a/web2/src/main.js b/web2/src/main.js index f9a3238b1..1595a0d58 100644 --- a/web2/src/main.js +++ b/web2/src/main.js @@ -1,9 +1,12 @@ import Vue from 'vue'; import moment from 'moment'; +import axios from 'axios'; import App from './App.vue'; import router from './router'; import vuetify from './plugins/vuetify'; +axios.defaults.baseURL = document.baseURI; + Vue.config.productionTip = false; Vue.filter('formatDate', (value) => (value ? moment(String(value)).fromNow() : '—')); diff --git a/web2/src/router/index.js b/web2/src/router/index.js index 08144ab04..dd2a0ee20 100644 --- a/web2/src/router/index.js +++ b/web2/src/router/index.js @@ -77,7 +77,6 @@ const routes = [ const router = new VueRouter({ mode: 'history', - base: process.env.BASE_URL, routes, }); diff --git a/web2/src/socket.js b/web2/src/socket.js index 78131af6b..49dd83207 100644 --- a/web2/src/socket.js +++ b/web2/src/socket.js @@ -1,8 +1,8 @@ import Socket from '@/lib/Socket'; const socket = new Socket(() => { - const protocol = document.location.protocol === 'https:' ? 'wss' : 'ws'; - return new WebSocket(`${protocol}://${document.location.host}/api/ws`); + const baseURI = `ws${document.baseURI.substr(4)}`; + return new WebSocket(`${baseURI}api/ws`); }); export default socket; diff --git a/web2/vue.config.js b/web2/vue.config.js index 3153f8790..d96498334 100644 --- a/web2/vue.config.js +++ b/web2/vue.config.js @@ -1,4 +1,12 @@ module.exports = { + chainWebpack: (config) => { + config.plugin('html') + .tap((args) => { + // eslint-disable-next-line no-param-reassign + args[0].minify = false; + return args; + }); + }, transpileDependencies: [ 'vuetify', ],