From f9c3b33cf2ab71386fb971e04c73bb1535f5692f Mon Sep 17 00:00:00 2001 From: fudgemasterultra Date: Mon, 28 Apr 2025 16:40:22 -0400 Subject: [PATCH 1/2] adding in .env.example file updated ignore, and swapped out for env value on src/api/call.js --- .env.example | 1 + .gitignore | 1 + src/api/call.js | 4 +--- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 .env.example 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/src/api/call.js b/src/api/call.js index 8bf04d78b..f92dbf94f 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,7 +45,7 @@ export function apiCall( secondAttempt = false, fetchMethod = fetch, ) { - return fetchMethod(POLICYENGINE_API + path, { + return fetchMethod(process.env.REACT_APP_POLICYENGINE_API + path, { method: method || (body ? "POST" : "GET"), headers: { "Content-Type": "application/json", From 1792484eaf304cf1e13222059dbf792ed36b6e6d Mon Sep 17 00:00:00 2001 From: fudgemasterultra Date: Mon, 28 Apr 2025 16:44:53 -0400 Subject: [PATCH 2/2] make file to copy .env.example on install, and added default value replacment for REACT_APP_POLICYENGINE_API --- Makefile | 1 + src/api/call.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) 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 f92dbf94f..fb5526187 100644 --- a/src/api/call.js +++ b/src/api/call.js @@ -45,13 +45,17 @@ export function apiCall( secondAttempt = false, fetchMethod = fetch, ) { - return fetchMethod(process.env.REACT_APP_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);