Skip to content

Commit

Permalink
move apiserver proxy detection out of bundle
Browse files Browse the repository at this point in the history
vite runtime url rendering has changed that it is evalutated before
everything on production bundle, so let's just be safer and move the
prerequisite out of bundle

we loss typescript tooling on this little bit of code, guess that just
the price need to be paid

fixes production bundle after vite 5.2.9

See: vitejs/vite#16184
  • Loading branch information
xdavidwu committed May 8, 2024
1 parent 9cce0d3 commit 160906b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, interactive-widget=resizes-content" />
<title>Sparkles</title>
<script>
const dns1123LabelFmt = '[a-z0-9]([-a-z0-9]*[a-z0-9])?';
const dns1123SubdomainFmt = `${dns1123LabelFmt}(\\.${dns1123LabelFmt})*`;
// TODO IANA_SVC_NAME/integer validation
const schemeNamePort = `((https?|):)?${dns1123SubdomainFmt}(:[^:/]*)?`;
const apiserverProxyRegex = new RegExp(`^/api/v1/namespaces/${dns1123SubdomainFmt}/(pods|services)/${schemeNamePort}/proxy/`);
const m = window.location.pathname.match(apiserverProxyRegex);
window.__base_url = m === null ? '%BASE_URL%' : m[0];
</script>
</head>
<body>
<div id="app"></div>
Expand Down
8 changes: 0 additions & 8 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ declare global {
}
}

const dns1123LabelFmt = '[a-z0-9]([-a-z0-9]*[a-z0-9])?';
const dns1123SubdomainFmt = `${dns1123LabelFmt}(\\.${dns1123LabelFmt})*`;
// TODO IANA_SVC_NAME/integer validation
const schemeNamePort = `((https?|):)?${dns1123SubdomainFmt}(:[^:/]*)?`;
const apiserverProxyRegex = new RegExp(`^/api/v1/namespaces/${dns1123SubdomainFmt}/(pods|services)/${schemeNamePort}/proxy/`);
const m = window.location.pathname.match(apiserverProxyRegex);
window.__base_url = m === null ? import.meta.env.BASE_URL : m[0];

const checkNamespacedResourcePermission =
(group: string, resource: string) => computedAsync(async () => {
const { selectedNamespace } = storeToRefs(useNamespaces());
Expand Down

0 comments on commit 160906b

Please sign in to comment.