Skip to content

Commit

Permalink
Merge pull request #239 from conda-incubator/runtime_configuration
Browse files Browse the repository at this point in the history
Runtime configuration
  • Loading branch information
anirrudh authored Aug 1, 2023
2 parents b7a872c + 2052b56 commit 718064a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
30 changes: 26 additions & 4 deletions src/docs/markdown/CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Configuration

The configuration for conda-store-ui, including the connection details to conda-store currently use `.env` files.
The configuration for conda-store-ui, including the connection details to conda-store, can be done :
- either at compile time, using a `.env` file.
- or at runtime, using `condaStoreConfig` variable

## Using `.env`

conda-store-ui looks for a `.env` file at runtime. Below, you'll find the options and the listed descriptions. You are welcome to copy
this configuration, otherwise, you can copy and rename the `.env.example` file provided in the repository.
## At compile time, using `.env`

conda-store-ui looks for a `.env` file when packing the bundle.
Below, you'll find the options and the listed descriptions. You are welcome to copy this configuration, otherwise, you can copy and rename the `.env.example` file provided in the repository.

Sample File:

Expand All @@ -18,6 +21,25 @@ REACT_APP_STYLE_TYPE=grayscale
REACT_APP_SHOW_LOGIN_ICON=true
```

## At runtime, using `condaStoreConfig`

When using a webpacked version of `conda-store-ui`, you might want to pass it a configuration.
In your HTML file, add the following **before** loading the react app :

```html
<script>
const condaStoreConfig = {
REACT_APP_AUTH_METHOD: "cookie",
REACT_APP_AUTH_TOKEN: "",
REACT_APP_STYLE_TYPE: "grayscale",
REACT_APP_SHOW_LOGIN_ICON: "true",
REACT_APP_API_URL: "http://localhost:5000/conda-store",
REACT_APP_LOGIN_PAGE_URL: "http://localhost:5000/conda-store/login?next=",
};
</script>
```


## Options

The possible options are stored in a key-value format.
Expand Down
28 changes: 25 additions & 3 deletions src/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,40 @@ export interface IPreferences {
showLoginIcon: boolean;
}

const { condaStoreConfig = {} } =
typeof window !== "undefined" && (window as any);

export const prefDefault: Readonly<IPreferences> = {
apiUrl: process.env.REACT_APP_API_URL ?? "http://localhost:5000/conda-store/",
apiUrl:
process.env.REACT_APP_API_URL ??
condaStoreConfig.REACT_APP_API_URL ??
"http://localhost:5000/conda-store/",

authMethod:
(process.env.REACT_APP_AUTH_METHOD as IPreferences["authMethod"]) ??
(condaStoreConfig.REACT_APP_AUTH_METHOD as IPreferences["authMethod"]) ??
"cookie",
authToken: process.env.REACT_APP_AUTH_TOKEN ?? "",

authToken:
process.env.REACT_APP_AUTH_TOKEN ??
condaStoreConfig.REACT_APP_AUTH_TOKEN ??
"",

loginUrl:
process.env.REACT_APP_LOGIN_PAGE_URL ??
condaStoreConfig.REACT_APP_LOGIN_PAGE_URL ??
"http://localhost:5000/conda-store/login?next=",
styleType: process.env.REACT_APP_STYLE_TYPE ?? "grayscale",

styleType:
process.env.REACT_APP_STYLE_TYPE ??
condaStoreConfig.REACT_APP_STYLE_TYPE ??
"grayscale",

showLoginIcon: process.env.REACT_APP_SHOW_LOGIN_ICON
? JSON.parse(process.env.REACT_APP_SHOW_LOGIN_ICON)
: condaStoreConfig !== undefined &&
condaStoreConfig.REACT_APP_SHOW_LOGIN_ICON !== undefined
? JSON.parse(condaStoreConfig.REACT_APP_SHOW_LOGIN_ICON)
: true
};

Expand Down

0 comments on commit 718064a

Please sign in to comment.