From 5b019c87bb07706cdd2dd251e10d3ecc54f0a0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tao=20Bror=20Bojl=C3=A9n?= Date: Thu, 21 Feb 2019 12:33:07 +0000 Subject: [PATCH] add development env var in frontend --- frontend/package.json | 2 +- frontend/src/util.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index c74f031..7230a36 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -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" diff --git a/frontend/src/util.ts b/frontend/src/util.ts index 1d1f2e7..8f6ded7 100644 --- a/frontend/src/util.ts +++ b/frontend/src/util.ts @@ -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 => { - 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()); +};