Skip to content

Commit a83032e

Browse files
feat: add context Header (#367)
1 parent 5237fc5 commit a83032e

File tree

8 files changed

+34
-4
lines changed

8 files changed

+34
-4
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
REACT_APP_BASE_API_URL="http://localhost:8080/api/v1"
1+
REACT_APP_BASE_API_URL=https://appserver.zenml.io/api/v1
22
REACT_APP_HUB_API_URL="https://hubapi.zenml.io"
33
REACT_APP_VERSION=$npm_package_version

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface TAction {
3535
interface TServerInfo {
3636
id: string;
3737
version: string;
38+
debug: boolean;
3839
deploymentType: string;
3940
databaseType: string;
4041
secretsStoreType: string;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@
113113
"eslint-plugin-prettier": "^3.1.4",
114114
"eslint-plugin-react": "^7.20.5",
115115
"eslint-plugin-redux-saga": "^1.1.3",
116+
"husky": "^8.0.0",
116117
"postcss": "^8.4.16",
117118
"prettier": "^2.0.5",
118119
"react-hooks-testing-library": "^0.6.0",
119-
"react-test-renderer": "^16.13.1",
120-
"husky": "^8.0.0"
120+
"react-test-renderer": "^16.13.1"
121121
},
122122
"engines": {
123123
"npm": ">=6.14.17",

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Provider } from 'react-redux';
44
import { RouteConfig } from './routes';
55

66
import configureStore from './redux/setup/storeSetup';
7+
import './utils/axios';
78
import Toaster from './ui/layouts/common/Toaster';
89

910
import 'bootstrap/dist/css/bootstrap-grid.min.css';

src/redux/reducers/serverInfoReducer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface State {
66
deploymentType: string;
77
databaseType: string;
88
secretsStoreType: string;
9+
debug: boolean;
910
}
1011

1112
interface Payload {
@@ -14,6 +15,7 @@ interface Payload {
1415
deployment_type: string;
1516
database_type: string;
1617
secrets_store_type: string;
18+
debug: boolean;
1719
}
1820

1921
export type Action = {
@@ -27,6 +29,7 @@ export const initialState: State = {
2729
id: '',
2830
secretsStoreType: '',
2931
version: '',
32+
debug: false,
3033
};
3134

3235
const newState = (info: Payload): State => ({
@@ -35,6 +38,7 @@ const newState = (info: Payload): State => ({
3538
id: info.id,
3639
secretsStoreType: info.secrets_store_type,
3740
version: info.version,
41+
debug: info.debug,
3842
});
3943

4044
export default function serverInfoReducer(

src/redux/setup/storeSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export const enhancers = getComposeWithEnhancers()(
2525
applyMiddleware(sagaMiddleware, logger),
2626
);
2727

28+
export const store = createStore(persistedReducer, enhancers);
2829
export default function configureStore(): any {
29-
const store = createStore(persistedReducer, enhancers);
3030
sagaMiddleware.run(rootSaga);
3131

3232
window.addEventListener(

src/utils/axios.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import axios from 'axios';
2+
import { getServerInfoFromRedux } from './store';
3+
4+
const axiosInterceptor = axios.interceptors.request.use(function (config) {
5+
if (config.url?.includes(process.env.REACT_APP_BASE_API_URL as string)) {
6+
config.headers['Source-Context'] = 'dashboard';
7+
}
8+
9+
if (config.url?.includes(process.env.REACT_APP_HUB_API_URL as string)) {
10+
const serverInfo = getServerInfoFromRedux();
11+
const debugFlag = serverInfo.debug;
12+
config.headers['Source-Context'] = 'dashboard';
13+
config.headers['Debug-Context'] = debugFlag || false;
14+
}
15+
16+
return config;
17+
});
18+
19+
export default axiosInterceptor;

src/utils/store.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { store } from '../redux/setup/storeSetup';
2+
3+
export function getServerInfoFromRedux(): TServerInfo {
4+
return (store.getState() || {}).persisted?.serverInfo || {};
5+
}

0 commit comments

Comments
 (0)