Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
feat(addon): define window variables for overriding server and API URLs
Browse files Browse the repository at this point in the history
To be used from the the addon where those will be dynamically rewritten
when opening from ingress.
  • Loading branch information
rchl committed Apr 11, 2021
1 parent c19f4b6 commit a52ac5b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<% stylesheets.forEach(stylesheet => { %><link rel="stylesheet" href="<%= stylesheet %>"><% }) %>
<link rel="stylesheet" href="./styles/custom.css">

<script>
window.SERVER_URL_OVERRIDE = null;
window.WS_URL_OVERRIDE = null;
window.AUTH_TOKEN_OVERRIDE = null;
</script>

<% javascripts.forEach(javascript => { %><script src="./<%= javascript %>"></script><% }) %>
</head>

Expand Down
2 changes: 1 addition & 1 deletion scripts/globals/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const debounce = function (func, wait, immediate) {

export const toAbsoluteServerURL = function (path) {
const startsWithProtocol = path.indexOf('http') === 0;
const url = startsWithProtocol ? path : window.CONFIG.serverUrl + '/' + path;
const url = startsWithProtocol ? path : (window.SERVER_URL_OVERRIDE || window.CONFIG.serverUrl) + '/' + path;
// Replace extra forward slashes but not in protocol.
return url.replace(/([^:])\/+/g, '$1/');
};
Expand Down
4 changes: 2 additions & 2 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ window.initApp = function () {
}

ApiProvider.setInitOptions({
wsUrl: window.CONFIG.wsUrl,
authToken: window.CONFIG.authToken,
wsUrl: window.WS_URL_OVERRIDE || window.CONFIG.wsUrl,
authToken: window.AUTH_TOKEN_OVERRIDE || window.CONFIG.authToken,
});

tmhDynamicLocaleProvider.localeLocationPattern('./locales/{{locale}}.js');
Expand Down
5 changes: 5 additions & 0 deletions types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Window {
AUTH_TOKEN_OVERRIDE: string | null
SERVER_URL_OVERRIDE: string | null
WS_URL_OVERRIDE: string | null
}

0 comments on commit a52ac5b

Please sign in to comment.