Skip to content

Commit

Permalink
fix: web_host option handing
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Nov 24, 2020
1 parent a36d23e commit 76390c4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
12 changes: 9 additions & 3 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
}

Expand Down
3 changes: 2 additions & 1 deletion web2/public/index.html
Original file line number Diff line number Diff line change
@@ -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">
Expand Down
3 changes: 3 additions & 0 deletions web2/src/main.js
Original file line number Diff line number Diff line change
@@ -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() : '—'));
Expand Down
1 change: 0 additions & 1 deletion web2/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const routes = [

const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes,
});

Expand Down
4 changes: 2 additions & 2 deletions web2/src/socket.js
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions web2/vue.config.js
Original file line number Diff line number Diff line change
@@ -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',
],
Expand Down

0 comments on commit 76390c4

Please sign in to comment.