Merge pull request #629 from ansible-semaphore/fix-routing-when-web-host-defined

Fix web_host option handing
This commit is contained in:
Denis Gukov 2020-11-24 17:41:43 +05:00 committed by GitHub
commit 77e8241a81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 7 deletions

View File

@ -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),
"<base href=\"/\">",
"<base href=\""+util.WebHostURL.String()+"\">",
"<base href=\""+baseURL+"\">",
1))
}

View File

@ -1,10 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.png">
<link rel="icon" href="favicon.png">
<title>Ansible Semaphore</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">

View File

@ -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() : '—'));

View File

@ -77,7 +77,6 @@ const routes = [
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes,
});

View File

@ -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;

View File

@ -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',
],