Skip to content

Commit 2f1eb2f

Browse files
Amy ChenAmy Chen
Amy Chen
authored and
Amy Chen
committed
Revert "read env variables from env.json if there"
This reverts commit 5d81f46.
1 parent 5d81f46 commit 2f1eb2f

File tree

4 files changed

+6
-75
lines changed

4 files changed

+6
-75
lines changed

public/env.json

-3
This file was deleted.

src/FhirClientProvider.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import FHIR from "fhirclient";
33
import Stack from "@mui/material/Stack";
44
import CircularProgress from "@mui/material/CircularProgress";
55
import { FhirClientContext } from "./FhirClientContext";
6-
import { fetchEnvData, getEnvs, queryPatientIdKey } from "./util/util";
6+
import { queryPatientIdKey } from "./util/util";
77
import ErrorComponent from "./components/ErrorComponent";
88

99
export default function FhirClientProvider(props) {
@@ -27,10 +27,6 @@ export default function FhirClientProvider(props) {
2727
});
2828
}, [client]);
2929

30-
useEffect(() => {
31-
fetchEnvData();
32-
console.log("environment variables ", getEnvs());
33-
}, []);
3430
useEffect(() => {
3531
FHIR.oauth2.ready().then(
3632
(client) => {

src/components/Launch.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import FHIR from "fhirclient";
33
import Stack from "@mui/material/Stack";
44
import CircularProgress from "@mui/material/CircularProgress";
55
import ErrorComponent from "./ErrorComponent";
6-
import { fetchEnvData, getEnv, queryPatientIdKey } from "../util/util.js";
6+
import { getEnv, queryPatientIdKey } from "../util/util.js";
77
import "../style/App.scss";
88

99
export default function Launch() {
1010
const [error, setError] = React.useState("");
1111

12-
React.useEffect(() => fetchEnvData(), []);
13-
1412
React.useEffect(() => {
1513
let authURL = "launch-context.json";
1614
const backendURL = getEnv("REACT_APP_BACKEND_URL");

src/util/util.js

+4-64
Original file line numberDiff line numberDiff line change
@@ -23,69 +23,9 @@ export function getFHIRResourcePaths(patientId) {
2323
});
2424
}
2525

26-
export function fetchEnvData() {
27-
if (window["appConfig"] && Object.keys(window["appConfig"]).length) {
28-
console.log("Window config variables added. ");
29-
return;
30-
}
31-
const setConfig = function () {
32-
if (!xhr.readyState === xhr.DONE) {
33-
return;
34-
}
35-
if (xhr.status !== 200) {
36-
console.log("Request failed! ");
37-
return;
38-
}
39-
var envObj = JSON.parse(xhr.responseText);
40-
window["appConfig"] = {};
41-
//assign window process env variables for access by app
42-
//won't be overridden when Node initializing env variables
43-
for (var key in envObj) {
44-
if (!window["appConfig"][key]) {
45-
window["appConfig"][key] = envObj[key];
46-
}
47-
}
48-
};
49-
var xhr = new XMLHttpRequest();
50-
xhr.open("GET", "/env.json", false);
51-
xhr.onreadystatechange = function () {
52-
//in the event of a communication error (such as the server going down),
53-
//or error happens when parsing data
54-
//an exception will be thrown in the onreadystatechange method when accessing the response properties, e.g. status.
55-
try {
56-
setConfig();
57-
} catch (e) {
58-
console.log("Caught exception " + e);
59-
}
60-
};
61-
try {
62-
xhr.send();
63-
} catch (e) {
64-
console.log("Request failed to send. Error: ", e);
65-
}
66-
xhr.ontimeout = function (e) {
67-
// XMLHttpRequest timed out.
68-
console.log("request to fetch env.json file timed out ", e);
69-
};
70-
}
71-
72-
export function getEnv(key) {
73-
//window application global variables
74-
if (window["appConfig"] && window["appConfig"][key])
75-
return window["appConfig"][key];
76-
const envDefined = typeof process !== "undefined" && process.env;
77-
//enviroment variables as defined in Node
78-
if (envDefined && process.env[key]) return process.env[key];
79-
return "";
80-
}
81-
82-
export function getEnvs() {
83-
const appConfig = window["appConfig"] ? window["appConfig"] : {};
84-
const processEnvs = process.env ? process.env : {};
85-
return {
86-
...appConfig,
87-
...processEnvs,
88-
};
89-
}
26+
export const getEnv = (key) => {
27+
if (!process || !process.env) return "";
28+
return process.env[key];
29+
};
9030

9131
export const queryPatientIdKey = 'launch_queryPatientId';

0 commit comments

Comments
 (0)