Skip to content

Commit 77e8241

Browse files
authored
Merge pull request #629 from ansible-semaphore/fix-routing-when-web-host-defined
Fix web_host option handing
2 parents a36d23e + 76390c4 commit 77e8241

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

api/router.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ func Route() *mux.Router {
5555
r.NotFoundHandler = http.HandlerFunc(servePublic)
5656

5757
webPath := "/"
58-
if util.WebHostURL != nil && util.WebHostURL.Hostname() != "0.0.0.0" {
59-
r.Host(util.WebHostURL.Hostname())
58+
if util.WebHostURL != nil {
6059
webPath = util.WebHostURL.Path
60+
if !strings.HasSuffix(webPath, "/") {
61+
webPath += "/"
62+
}
6163
}
6264

6365
r.Use(mux.CORSMethodMiddleware(r))
@@ -281,9 +283,13 @@ func servePublic(w http.ResponseWriter, r *http.Request) {
281283

282284
// replace base path
283285
if util.WebHostURL != nil && path == htmlPrefix+"/index.html" {
286+
baseURL := util.WebHostURL.String()
287+
if !strings.HasSuffix(baseURL, "/") {
288+
baseURL += "/"
289+
}
284290
res = []byte(strings.Replace(string(res),
285291
"<base href=\"/\">",
286-
"<base href=\""+util.WebHostURL.String()+"\">",
292+
"<base href=\""+baseURL+"\">",
287293
1))
288294
}
289295

web2/public/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<base href="/">
45
<meta charset="utf-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
67
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7-
<link rel="icon" href="<%= BASE_URL %>favicon.png">
8+
<link rel="icon" href="favicon.png">
89
<title>Ansible Semaphore</title>
910
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
1011
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">

web2/src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import Vue from 'vue';
22
import moment from 'moment';
3+
import axios from 'axios';
34
import App from './App.vue';
45
import router from './router';
56
import vuetify from './plugins/vuetify';
67

8+
axios.defaults.baseURL = document.baseURI;
9+
710
Vue.config.productionTip = false;
811

912
Vue.filter('formatDate', (value) => (value ? moment(String(value)).fromNow() : '—'));

web2/src/router/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const routes = [
7777

7878
const router = new VueRouter({
7979
mode: 'history',
80-
base: process.env.BASE_URL,
8180
routes,
8281
});
8382

web2/src/socket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Socket from '@/lib/Socket';
22

33
const socket = new Socket(() => {
4-
const protocol = document.location.protocol === 'https:' ? 'wss' : 'ws';
5-
return new WebSocket(`${protocol}://${document.location.host}/api/ws`);
4+
const baseURI = `ws${document.baseURI.substr(4)}`;
5+
return new WebSocket(`${baseURI}api/ws`);
66
});
77

88
export default socket;

web2/vue.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
module.exports = {
2+
chainWebpack: (config) => {
3+
config.plugin('html')
4+
.tap((args) => {
5+
// eslint-disable-next-line no-param-reassign
6+
args[0].minify = false;
7+
return args;
8+
});
9+
},
210
transpileDependencies: [
311
'vuetify',
412
],

0 commit comments

Comments
 (0)