add development env var in frontend

This commit is contained in:
Tao Bror Bojlén 2019-02-21 12:33:07 +00:00
parent 795ad67e8b
commit 5b019c87bb
No known key found for this signature in database
GPG Key ID: C6EC7AAB905F9E6F
2 changed files with 9 additions and 9 deletions

View File

@ -22,7 +22,7 @@
"sanitize-html": "^1.18.4"
},
"scripts": {
"start": "react-scripts-ts start",
"start": "NODE_ENV=development react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject"

View File

@ -1,11 +1,11 @@
import fetch from 'cross-fetch';
import fetch from "cross-fetch";
const API_ROOT = "https://api.fediverse.space/api/v1/"
// const API_ROOT = "http://localhost:8000/api/v1/"
const API_ROOT =
process.env.NODE_ENV === "development" ? "http://localhost:8000/api/v1/" : "https://api.fediverse.space/api/v1/";
export const getFromApi = (path: string): Promise<any> => {
const domain = API_ROOT.endsWith("/") ? API_ROOT : API_ROOT + "/";
path = path.endsWith("/") ? path : path + "/";
path += "?format=json"
return fetch(domain + path).then(response => response.json());
}
const domain = API_ROOT.endsWith("/") ? API_ROOT : API_ROOT + "/";
path = path.endsWith("/") ? path : path + "/";
path += "?format=json";
return fetch(domain + path).then(response => response.json());
};