Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Welcome from './components/Welcome';
import useOidcMfa from './hooks/useOidcMfa';
import { env } from './env';
import { logger } from './utils/logger';
import { ensureUrlHasOrigin } from './utils/url';

const projectRegex = /^P([a-zA-Z0-9]{27}|[a-zA-Z0-9]{31})$/;
const ssoAppRegex = /^[a-zA-Z0-9\-_]{1,30}$/;
Expand Down Expand Up @@ -48,7 +49,9 @@ const App = () => {
const defaultFaviconUrl =
env.REACT_APP_DEFAULT_FAVICON_URL || env.DEFAULT_FAVICON_URL || '';
const faviconUrlTemplate =
env.REACT_APP_FAVICON_URL_TEMPLATE || env.REACT_APP_FAVICON_URL || '';
ensureUrlHasOrigin(env.REACT_APP_FAVICON_URL_TEMPLATE) ||
env.REACT_APP_FAVICON_URL ||
'';

// Force origin base URL
if (env.REACT_APP_USE_ORIGIN_BASE_URL === 'true')
Expand Down
5 changes: 2 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import ReactDOM from 'react-dom/client';
import App from './App';
import { env } from './env';
import Error from './Error';
import { ensureUrlHasOrigin } from './utils/url';

const contentBaseUrl = env.REACT_APP_CONTENT_BASE_URL?.startsWith('/')
? window.location.origin + env.REACT_APP_CONTENT_BASE_URL
: env.REACT_APP_CONTENT_BASE_URL;
const contentBaseUrl = ensureUrlHasOrigin(env.REACT_APP_CONTENT_BASE_URL);

if (contentBaseUrl) {
localStorage.setItem('base.content.url', contentBaseUrl);
Expand Down
12 changes: 12 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Ensures a URL has an origin by prepending the current window's origin if needed
* @param url The URL to process
* @returns A URL with origin or empty string if input is undefined
*/
export const ensureUrlHasOrigin = (url?: string): string => {
if (!url) {
return '';
}

return url.startsWith('/') ? `${window.location.origin}${url}` : url;
};
Loading