Add API proxy (#41)

This commit is contained in:
Ilya Boyandin
2022-04-20 17:35:14 +02:00
committed by GitHub
parent 6bc321377a
commit 51bcdc4467
2 changed files with 7 additions and 5 deletions

View File

@@ -199,5 +199,6 @@
},
"eslintConfig": {
"extends": "react-app"
}
},
"proxy": "https://ukraine.bellingcat.com/ukraine-server"
}

View File

@@ -268,14 +268,15 @@ export function injectSource(id) {
};
}
const API_ROOT =
process.env.NODE_ENV === "development" ? "" : process.env.SERVER_ROOT;
export function urlFromEnv(ext) {
if (process.env[ext]) {
if (!Array.isArray(process.env[ext])) {
return [`${process.env.SERVER_ROOT}${process.env[ext]}`];
return [`${API_ROOT}${process.env[ext]}`];
} else {
return process.env[ext].map(
(suffix) => `${process.env.SERVER_ROOT}${suffix}`
);
return process.env[ext].map((suffix) => `${API_ROOT}${suffix}`);
}
} else {
return null;