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()); +};