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

Commit

Permalink
fix: allow overriding REST API domain for ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Apr 15, 2021
1 parent f95b918 commit 5987c16
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
<link rel="stylesheet" href="./styles/custom.css">

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

<% javascripts.forEach(javascript => { %><script src="./<%= javascript %>"></script><% }) %>
Expand Down
4 changes: 2 additions & 2 deletions scripts/globals/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export const debounce = function (func, wait, immediate) {
};
};

export const toAbsoluteServerURL = function (path) {
export const toAbsoluteServerURL = function (path, serverUrlOverride = false) {
const startsWithProtocol = path.indexOf('http') === 0;
const url = startsWithProtocol ? path : (window.SERVER_URL_OVERRIDE || window.CONFIG.serverUrl) + '/' + path;
const url = startsWithProtocol ? path : (serverUrlOverride || window.SERVER_URL_OVERRIDE || window.CONFIG.serverUrl) + '/' + path;
// Replace extra forward slashes but not in protocol.
return url.replace(/([^:])\/+/g, '$1/');
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ App.provider('Api', function () {

$Api.prototype.rest = function (requestStub) {
const request = angular.copy(requestStub);
request.url = toAbsoluteServerURL(request.url);
request.url = toAbsoluteServerURL(request.url, window.REST_URL_OVERRIDE);
request.headers = request.headers || {};
request.headers.Authorization = 'Bearer ' + this._token;
return $http(request)
Expand Down
1 change: 1 addition & 0 deletions types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface Window {
AUTH_TOKEN_OVERRIDE: string | null
REST_URL_OVERRIDE: string | null
SERVER_URL_OVERRIDE: string | null
WS_URL_OVERRIDE: string | null
}

0 comments on commit 5987c16

Please sign in to comment.