[ARVADOS-WORKBENCH2] created: 1.1.4-292-g2215210
Git user
git at public.curoverse.com
Mon Jul 16 05:32:25 EDT 2018
at 22152102405a1407355d42a32385efd0d83bbc9c (commit)
commit 22152102405a1407355d42a32385efd0d83bbc9c
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Mon Jul 16 11:31:40 2018 +0200
Implement configuration fetching during runtime
Feature #13817
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/.env b/.env
index 13aaad5..a523865 100644
--- a/.env
+++ b/.env
@@ -2,4 +2,5 @@
#
# SPDX-License-Identifier: AGPL-3.0
+REACT_APP_ARVADOS_CONFIG_URL=/config.json
REACT_APP_ARVADOS_API_HOST=https://qr1hi.arvadosapi.com
\ No newline at end of file
diff --git a/README.md b/README.md
index 864a54f..998d424 100644
--- a/README.md
+++ b/README.md
@@ -26,12 +26,22 @@ yarn install
yarn build
</pre>
-### Configuration
+### Build time configuration
You can customize project global variables using env variables. Default values are placed in the `.env` file.
Example:
```
-REACT_APP_ARVADOS_API_HOST=localhost:8000 yarn start
+REACT_APP_ARVADOS_CONFIG_URL=config.json yarn build
+```
+
+### Run time configuration
+The app will fetch runtime configuration when starting. By default it will try to fetch `/config.json`. You can customize this url using build time configuration.
+
+Currently this configuration schema is supported:
+```
+{
+ "API_HOST": "string"
+}
```
### Licensing
diff --git a/src/common/api/server-api.ts b/src/common/api/server-api.ts
index 330ce65..5beecd4 100644
--- a/src/common/api/server-api.ts
+++ b/src/common/api/server-api.ts
@@ -18,3 +18,7 @@ export function setServerApiAuthorizationHeader(token: string) {
export function removeServerApiAuthorizationHeader() {
delete serverApi.defaults.headers.common.Authorization;
}
+
+export const setBaseUrl = (url: string) => {
+ serverApi.defaults.baseURL = url + "/arvados/v1";
+};
diff --git a/src/common/config.ts b/src/common/config.ts
new file mode 100644
index 0000000..4b4a52a
--- /dev/null
+++ b/src/common/config.ts
@@ -0,0 +1,23 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import Axios from "../../node_modules/axios";
+
+export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
+
+export interface Config {
+ API_HOST: string;
+}
+
+const defaultConfig: Config = {
+ API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || ""
+};
+
+export const fetchConfig = () => {
+ return Axios
+ .get<Config>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
+ .then(response => response.data)
+ .catch(() => Promise.resolve(defaultConfig));
+};
+
diff --git a/src/index.tsx b/src/index.tsx
index a06b485..1022496 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -17,39 +17,36 @@ import { authService } from "./services/services";
import { getProjectList } from "./store/project/project-action";
import { MuiThemeProvider } from '@material-ui/core/styles';
import { CustomTheme } from './common/custom-theme';
-import CommonResourceService from './common/api/common-resource-service';
-import { CollectionResource } from './models/collection';
-import { serverApi } from './common/api/server-api';
-import { ProcessResource } from './models/process';
-
-const history = createBrowserHistory();
-
-const store = configureStore(history);
-
-store.dispatch(authActions.INIT());
-store.dispatch<any>(getProjectList(authService.getUuid()));
-
-// const service = new CommonResourceService<CollectionResource>(serverApi, "collections");
-// service.create({ ownerUuid: "qr1hi-j7d0g-u55bcc7fa5w7v4p", name: "Collection 1 short title"});
-// service.create({ ownerUuid: "qr1hi-j7d0g-u55bcc7fa5w7v4p", name: "Collection 2 long long long title"});
-
-// const processService = new CommonResourceService<ProcessResource>(serverApi, "container_requests");
-// processService.create({ ownerUuid: "qr1hi-j7d0g-u55bcc7fa5w7v4p", name: "Process 1 short title"});
-// processService.create({ ownerUuid: "qr1hi-j7d0g-u55bcc7fa5w7v4p", name: "Process 2 long long long title" });
-
-const App = () =>
- <MuiThemeProvider theme={CustomTheme}>
- <Provider store={store}>
- <ConnectedRouter history={history}>
- <div>
- <Route path="/" component={Workbench} />
- <Route path="/token" component={ApiToken} />
- </div>
- </ConnectedRouter>
- </Provider>
- </MuiThemeProvider>;
-
-ReactDOM.render(
- <App />,
- document.getElementById('root') as HTMLElement
-);
+import { fetchConfig } from './common/config';
+import { setBaseUrl } from './common/api/server-api';
+
+fetchConfig()
+ .then(config => {
+
+ setBaseUrl(config.API_HOST);
+
+ const history = createBrowserHistory();
+ const store = configureStore(history);
+
+ store.dispatch(authActions.INIT());
+ store.dispatch<any>(getProjectList(authService.getUuid()));
+
+ const App = () =>
+ <MuiThemeProvider theme={CustomTheme}>
+ <Provider store={store}>
+ <ConnectedRouter history={history}>
+ <div>
+ <Route path="/" component={Workbench} />
+ <Route path="/token" component={ApiToken} />
+ </div>
+ </ConnectedRouter>
+ </Provider>
+ </MuiThemeProvider>;
+
+ ReactDOM.render(
+ <App />,
+ document.getElementById('root') as HTMLElement
+ );
+ });
+
+
commit e21e064af352066148e4f45c5c4594ae4b05daf3
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Mon Jul 16 10:49:18 2018 +0200
Add AuthService constructor with serverApi param
Feature #13817
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index e953a75..5b21a61 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -2,8 +2,9 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import { API_HOST, serverApi } from "../../common/api/server-api";
+import { API_HOST } from "../../common/api/server-api";
import { User } from "../../models/user";
+import { AxiosInstance } from "../../../node_modules/axios";
export const API_TOKEN_KEY = 'apiToken';
export const USER_EMAIL_KEY = 'userEmail';
@@ -23,6 +24,8 @@ export interface UserDetailsResponse {
export default class AuthService {
+ constructor(protected serverApi: AxiosInstance) { }
+
public saveApiToken(token: string) {
localStorage.setItem(API_TOKEN_KEY, token);
}
@@ -82,7 +85,7 @@ export default class AuthService {
}
public getUserDetails = (): Promise<User> => {
- return serverApi
+ return this.serverApi
.get<UserDetailsResponse>('/users/current')
.then(resp => ({
email: resp.data.email,
diff --git a/src/services/services.ts b/src/services/services.ts
index 143e97b..88f6ffa 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -7,6 +7,6 @@ import GroupsService from "./groups-service/groups-service";
import { serverApi } from "../common/api/server-api";
import ProjectService from "./project-service/project-service";
-export const authService = new AuthService();
+export const authService = new AuthService(serverApi);
export const groupsService = new GroupsService(serverApi);
export const projectService = new ProjectService(serverApi);
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list