Skip to content

Commit

Permalink
Add config option REACT_APP_URL_BASENAME (#431)
Browse files Browse the repository at this point in the history
* Add config option REACT_APP_URL_BASENAME

* update preferences class
  • Loading branch information
gabalafou authored Oct 21, 2024
1 parent dc1a198 commit 0cb7011
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ REACT_APP_SHOW_AUTH_BUTTON=true
REACT_APP_LOGOUT_PAGE_URL=http://localhost:8080/conda-store/logout?next=/
REACT_APP_ROUTER_TYPE=browser

# If you need to mount the React app at some URL path other than "/". This value
# is passed directly to React Router, see:
# https://reactrouter.com/en/main/routers/create-browser-router#optsbasename
# REACT_APP_URL_BASENAME="/conda-store"

# If you want to use a version other than the pinned conda-store-server version
# Set the CONDA_STORE_SERVER_VERSION to the package version that you want
# CONDA_STORE_SERVER_VERSION="2024.3.1"
6 changes: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ export class App<
// }

render(): React.ReactNode {
const { routerType, urlBasename: basename } = this.state.pref;

const router =
this.state.pref.routerType === "memory"
routerType === "memory"
? createMemoryRouter(routes, { initialEntries: ["/"] })
: createBrowserRouter(routes);
: createBrowserRouter(routes, { basename });

return (
<PrefContext.Provider value={this.state.pref}>
Expand Down
17 changes: 16 additions & 1 deletion src/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface IPreferences {
// the URL routes in the browser address bar are for JupyterLab, not for
// conda-store-ui.
routerType: "browser" | "memory";

// urlBasename - Defaults to "/" but can be changed if the app needs to be
// mounted at a different URL path, such as "/conda-store"
urlBasename: string;
}

const { condaStoreConfig = {} } =
Expand Down Expand Up @@ -61,7 +65,12 @@ export const prefDefault: Readonly<IPreferences> = {
routerType:
process.env.REACT_APP_ROUTER_TYPE ??
condaStoreConfig.REACT_APP_ROUTER_TYPE ??
"browser"
"browser",

urlBasename:
process.env.REACT_APP_URL_BASENAME ??
condaStoreConfig.REACT_APP_URL_BASENAME ??
"/"
};

export class Preferences implements IPreferences {
Expand Down Expand Up @@ -101,6 +110,10 @@ export class Preferences implements IPreferences {
return this._routerType;
}

get urlBasename() {
return this._urlBasename;
}

set(pref: IPreferences) {
this._apiUrl = pref.apiUrl;
this._authMethod = pref.authMethod;
Expand All @@ -110,6 +123,7 @@ export class Preferences implements IPreferences {
this._showAuthButton = pref.showAuthButton;
this._logoutUrl = pref.logoutUrl;
this._routerType = pref.routerType;
this._urlBasename = pref.urlBasename;
}

private _apiUrl: IPreferences["apiUrl"];
Expand All @@ -120,6 +134,7 @@ export class Preferences implements IPreferences {
private _showAuthButton: IPreferences["showAuthButton"];
private _logoutUrl: IPreferences["logoutUrl"];
private _routerType: IPreferences["routerType"];
private _urlBasename: IPreferences["urlBasename"];
}

export const prefGlobal = new Preferences();
Expand Down

0 comments on commit 0cb7011

Please sign in to comment.