Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option REACT_APP_URL_BASENAME #431

Merged
merged 2 commits into from
Oct 21, 2024
Merged
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: 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