Skip to content

Commit

Permalink
Add config option REACT_APP_URL_BASENAME
Browse files Browse the repository at this point in the history
  • Loading branch information
gabalafou committed Oct 18, 2024
1 parent dc1a198 commit a5d6433
Show file tree
Hide file tree
Showing 3 changed files with 19 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
11 changes: 10 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 {

Check failure on line 76 in src/preferences.tsx

View workflow job for this annotation

GitHub Actions / Build conda-store-ui

Class 'Preferences' incorrectly implements interface 'IPreferences'.
Expand Down

0 comments on commit a5d6433

Please sign in to comment.