Skip to content

Commit

Permalink
[Feat] ConfigurationContext
Browse files Browse the repository at this point in the history
Created a context to hold application config data.
This is to replace configuration.ts as it was creating issues.
Vaigly references #21.
  • Loading branch information
angel-penchev committed Oct 23, 2021
1 parent 7e73d8c commit 97e8b6b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
5 changes: 1 addition & 4 deletions client/.env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
NODE_ENV=

APP_PORT=
APP_PREFIX=

API_ROOT=
REACT_APP_API_ROOT=
14 changes: 8 additions & 6 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import PrimaryView from './components/PrimaryView/PrimaryView';
import * as dotenv from 'dotenv';

import React, { FC } from 'react';
import { Container } from '@mui/material';

const environment = process.env.NODE_ENV;
const envFilePath = !environment ? '.env' : `.env.${environment}`;
dotenv.config({ path: envFilePath });

const App: FC<{}> = () => {
return (
<div className="App">
<PrimaryView />
</div>
);
return <Container className="App"></Container>;
};

export default App;
18 changes: 0 additions & 18 deletions client/src/configuration.ts

This file was deleted.

19 changes: 19 additions & 0 deletions client/src/contexts/ConfigurationContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { createContext } from 'react';

const configuration = {
api: {
root: process.env.REACT_APP_API_ROOT || '',
},
};
const configurationContext = createContext(configuration);

const ConfigurationContext = () => {
return (
<configurationContext.Provider
value={configuration}
></configurationContext.Provider>
);
};

export { configurationContext };
export default ConfigurationContext;
5 changes: 1 addition & 4 deletions client/types/enviourment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ declare global {
export interface ProcessEnv {
NODE_ENV: string;

APP_PORT?: string;
APP_PREFIX?: string;

API_ROOT?: string;
REACT_APP_API_ROOT?: string;
}
}
}
Expand Down

0 comments on commit 97e8b6b

Please sign in to comment.