diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..045ad4d0c --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +REACT_APP_POLICYENGINE_API=https://api.policyengine.org \ No newline at end of file diff --git a/.gitignore b/.gitignore index f0bee50c5..43628a3dc 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ yarn-error.log* .idea venv/* +.env \ No newline at end of file diff --git a/Makefile b/Makefile index 2639b6777..c7a7b72d8 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ REACT_APP_DEBUG ?= false install: npm ci + cp .env.example .env pip3 install -U black build: diff --git a/src/api/call.js b/src/api/call.js index 8bf04d78b..fb5526187 100644 --- a/src/api/call.js +++ b/src/api/call.js @@ -4,8 +4,6 @@ import { buildVariableTree, getTreeLeavesInOrder } from "./variables"; import { wrappedJsonStringify, wrappedResponseJson } from "../data/wrappedJson"; import { useAuthenticatedFetch } from "../hooks/useAuthenticatedFetch"; -const POLICYENGINE_API = "https://api.policyengine.org"; - /** * returns an api call function that can be used to make requests * against the policyengine api endpoint. @@ -47,13 +45,17 @@ export function apiCall( secondAttempt = false, fetchMethod = fetch, ) { - return fetchMethod(POLICYENGINE_API + path, { - method: method || (body ? "POST" : "GET"), - headers: { - "Content-Type": "application/json", + return fetchMethod( + process.env.REACT_APP_POLICYENGINE_API || + "https://api.policyengine.org" + path, + { + method: method || (body ? "POST" : "GET"), + headers: { + "Content-Type": "application/json", + }, + body: body ? wrappedJsonStringify(body) : null, }, - body: body ? wrappedJsonStringify(body) : null, - }).then((response) => { + ).then((response) => { // If the response is a 500, try again once. if (response.status === 500 && !secondAttempt) { return apiCall(path, body, method, true);