From d37ecf91d1ca2ebfbdb995451f8a459ff6f1ebb8 Mon Sep 17 00:00:00 2001 From: Eric Herbrandson Date: Fri, 15 Mar 2019 10:59:24 -0500 Subject: [PATCH] Fixing a few issues with concatenating urls --- README.md | 9 +-------- client/src/services/apiProxy.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d68edd3..084ab51 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,8 @@ NOTE: never trust a file downloaded from the internet. Make sure to review the c kubectl apply -f https://raw.githubusercontent.com/herbrandson/k8dash/master/kubernetes-k8dash.yaml ``` -To access k8dash from your local workstation you must create a secure channel to your Kubernetes cluster. Run the following command: +To access k8dash, you must make it publicly visible. If you have an ingress server setup, you can accomplish by adding a route like the following -``` bash -kubectl proxy -``` - -You can then access the ui at [http://localhost:8001/api/v1/namespaces/kube-system/services/http:k8dash:/proxy/](http://localhost:8001/api/v1/namespaces/kube-system/services/http:k8dash:/proxy/) - -Alternatively, if you have an ingress server setup, you can simply add a route like the following ``` yaml kind: Ingress diff --git a/client/src/services/apiProxy.js b/client/src/services/apiProxy.js index 2ffe28b..577e88c 100644 --- a/client/src/services/apiProxy.js +++ b/client/src/services/apiProxy.js @@ -1,7 +1,7 @@ import log from '../utils/log'; -const {host} = window.location; -const nonHashedUrl = window.location.href.replace(window.location.hash, ''); +const {host, href, hash, search} = window.location; +const nonHashedUrl = href.replace(hash, '').replace(search, ''); const BASE_HTTP_URL = host === 'localhost:4653' ? 'http://localhost:4654' : nonHashedUrl; const BASE_WS_URL = BASE_HTTP_URL.replace('http', 'ws'); @@ -37,8 +37,8 @@ export async function request(path, params, autoLogoutOnAuthError = true) { const token = getToken(); if (token) opts.headers.Authorization = `Bearer ${token}`; - const fullUrl = window.url.resolve(BASE_HTTP_URL, path); - const response = await fetch(fullUrl, opts); + const url = combinePath(BASE_HTTP_URL, path); + const response = await fetch(url, opts); if (!response.ok) { const {status, statusText} = response; @@ -86,8 +86,8 @@ function connectStream(path, cb, onFail, isJson) { 'base64.binary.k8s.io', ]; - const fullUrl = window.url.resolve(BASE_WS_URL, path); - const socket = new WebSocket(fullUrl, protocols); + const url = combinePath(BASE_WS_URL, path); + const socket = new WebSocket(url, protocols); socket.onmessage = onMessage; socket.onclose = onClose; socket.onerror = onError; @@ -179,3 +179,9 @@ function push(results, cb) { const items = Object.values(results); cb(items); } + +function combinePath(base, path) { + if (base.endsWith('/')) base = base.slice(0, -1); // eslint-disable-line no-param-reassign + if (path.startsWith('/')) path = path.slice(1); // eslint-disable-line no-param-reassign + return `${base}/${path}`; +}