Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_POLICYENGINE_API=https://api.policyengine.org
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ yarn-error.log*
.idea

venv/*
.env
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ REACT_APP_DEBUG ?= false

install:
npm ci
cp .env.example .env
pip3 install -U black

build:
Expand Down
18 changes: 10 additions & 8 deletions src/api/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Would it be more advantageous to set the POLICYENGINE_API constant as either the env var or standard address, then use that constant in the fetch method?

This would enable other components, as needed, to import the constant

"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);
Expand Down
Loading