From 6cd1260d5ffae8ef5183cbf51e29385946a7758e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tao=20Bror=20Bojl=C3=A9n?= Date: Wed, 17 Jul 2019 23:51:49 +0300 Subject: [PATCH] set up staging frontend to use staging backend --- frontend/README.md | 8 ++++++++ frontend/src/util.ts | 8 ++++++-- netlify.toml | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 netlify.toml diff --git a/frontend/README.md b/frontend/README.md index d5b4fc9..0652bb2 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,3 +1,11 @@ +# fediverse.space frontend + +The React frontend for [fediverse.space](https://fediverse.space). Written in Typescript. + +- Set the environment variable `REACT_APP_STAGING=true` when building to use the staging backend. + +# Default README + This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). Below you will find some information on how to perform common tasks.
diff --git a/frontend/src/util.ts b/frontend/src/util.ts index 3ff0f3d..429ede0 100644 --- a/frontend/src/util.ts +++ b/frontend/src/util.ts @@ -1,7 +1,11 @@ import fetch from "cross-fetch"; -const API_ROOT = - process.env.NODE_ENV === "development" ? "http://localhost:4000/api/" : "https://backend.fediverse.space/api/"; +let API_ROOT = "http://localhost:4000/api/"; +if (["true", true, 1, "1"].indexOf(process.env.REACT_APP_STAGING || "") > -1) { + API_ROOT = "https://phoenix.api-develop.fediverse.space/api/"; +} else if (process.env.NODE_ENV === "production") { + API_ROOT = "https://phoenix.api.fediverse.space/api/"; +} export const getFromApi = (path: string): Promise => { const domain = API_ROOT.endsWith("/") ? API_ROOT : API_ROOT + "/"; diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..4438afa --- /dev/null +++ b/netlify.toml @@ -0,0 +1,9 @@ +[build] + base = "frontend/" + publish = "frontend/build/" + +[context.develop.environment] + REACT_APP_STAGING = "true" + +[context.branch-deploy.environment] + REACT_APP_STAGING = "true"