From 4cb63ccaba8dfb39e6ce6db300c9bc4ffe76fa65 Mon Sep 17 00:00:00 2001 From: Anne-Marie Date: Fri, 31 Jul 2020 17:37:59 +0200 Subject: [PATCH 1/7] use login url for dev environment --- src/utils/token.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/token.ts b/src/utils/token.ts index 1327f17..563c577 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -1,5 +1,10 @@ const OAUTH_KEY_STORAGE_KEY = "auth:token"; +const { NODE_ENV } = process.env +if (!NODE_ENV) { + throw new Error('The NODE_ENV environment variable is required but was not specified.') +} + function getTokenFromUrl() { const searchParams = new URLSearchParams(document.location.hash); @@ -29,9 +34,13 @@ export function getOauthTokenOrRedirect(): string { // will be redirected first return ""; } +const isDevEnv = NODE_ENV === 'development'; + +export const LOGIN_PAGE_URL = isDevEnv ? "http://localhost:3000/auth/google_oauth2" : "https://octo-moss-back.herokuapp.com/auth/google_oauth2"; + +console.log('LOGIN_PAGE_URL', LOGIN_PAGE_URL); +console.log('isDevEnv', isDevEnv); -export const LOGIN_PAGE_URL = - "https://octo-moss-back.herokuapp.com/auth/google_oauth2"; export function redirectToLoginPage() { window.location.href = `${LOGIN_PAGE_URL}?redirect_to=${window.location.href}`; From 840e127d6620542df33c4d445692d62f458a4108 Mon Sep 17 00:00:00 2001 From: Anne-Marie Date: Tue, 4 Aug 2020 17:35:53 +0200 Subject: [PATCH 2/7] redirect to local login url when not in production env --- .env | 3 +++ .env.sample | 6 ++++++ src/utils/token.ts | 8 +++----- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..f0ce87f --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +REACT_APP_API_URL='http://localhost:3000/api/v1 +REACT_APP_LOCAL_BASE_URL='http://localhost:3001' +REACT_APP_OTHER_BASE_URL='https://octo-moss-back.herokuapp.com' diff --git a/.env.sample b/.env.sample index b4895a1..626b6b8 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1,7 @@ +<<<<<<< HEAD REACT_APP_API_URL='http://localhost:3000/api/v1/' +======= +REACT_APP_API_URL= +REACT_APP_LOCAL_BASE_URL= +REACT_APP_OTHER_BASE_URL= +>>>>>>> 4ae8399... redirect to local login url when not in production env diff --git a/src/utils/token.ts b/src/utils/token.ts index 563c577..db78323 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -4,6 +4,7 @@ const { NODE_ENV } = process.env if (!NODE_ENV) { throw new Error('The NODE_ENV environment variable is required but was not specified.') } +const isProdEnv = NODE_ENV === 'production'; function getTokenFromUrl() { const searchParams = new URLSearchParams(document.location.hash); @@ -34,13 +35,10 @@ export function getOauthTokenOrRedirect(): string { // will be redirected first return ""; } -const isDevEnv = NODE_ENV === 'development'; -export const LOGIN_PAGE_URL = isDevEnv ? "http://localhost:3000/auth/google_oauth2" : "https://octo-moss-back.herokuapp.com/auth/google_oauth2"; - -console.log('LOGIN_PAGE_URL', LOGIN_PAGE_URL); -console.log('isDevEnv', isDevEnv); +const AUTH_BASE_URL = isProdEnv ? process.env.REACT_APP_OTHER_BASE_URL : process.env.REACT_APP_LOCAL_BASE_URL; +const LOGIN_PAGE_URL = `${AUTH_BASE_URL}/auth/google_oauth2` export function redirectToLoginPage() { window.location.href = `${LOGIN_PAGE_URL}?redirect_to=${window.location.href}`; From 41c0728ad5a888f2606567e7ed9fdc9cf419e9cb Mon Sep 17 00:00:00 2001 From: Anne-Marie Date: Thu, 6 Aug 2020 11:34:31 +0200 Subject: [PATCH 3/7] use prod or dev env url for login page url --- .env | 3 --- src/utils/token.ts | 10 +--------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index f0ce87f..0000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -REACT_APP_API_URL='http://localhost:3000/api/v1 -REACT_APP_LOCAL_BASE_URL='http://localhost:3001' -REACT_APP_OTHER_BASE_URL='https://octo-moss-back.herokuapp.com' diff --git a/src/utils/token.ts b/src/utils/token.ts index db78323..17133c6 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -1,11 +1,5 @@ const OAUTH_KEY_STORAGE_KEY = "auth:token"; -const { NODE_ENV } = process.env -if (!NODE_ENV) { - throw new Error('The NODE_ENV environment variable is required but was not specified.') -} -const isProdEnv = NODE_ENV === 'production'; - function getTokenFromUrl() { const searchParams = new URLSearchParams(document.location.hash); @@ -36,9 +30,7 @@ export function getOauthTokenOrRedirect(): string { return ""; } -const AUTH_BASE_URL = isProdEnv ? process.env.REACT_APP_OTHER_BASE_URL : process.env.REACT_APP_LOCAL_BASE_URL; - -const LOGIN_PAGE_URL = `${AUTH_BASE_URL}/auth/google_oauth2` +const LOGIN_PAGE_URL = `${process.env.REACT_APP_BASE_URL}/auth/google_oauth2` export function redirectToLoginPage() { window.location.href = `${LOGIN_PAGE_URL}?redirect_to=${window.location.href}`; From 592356e7132d853a2e018955a949ab8d3f2995bc Mon Sep 17 00:00:00 2001 From: Anne-Marie Date: Thu, 6 Aug 2020 14:40:23 +0200 Subject: [PATCH 4/7] rename en variable for better understanding --- .env.sample | 7 +------ src/utils/token.ts | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.env.sample b/.env.sample index 626b6b8..359e09b 100644 --- a/.env.sample +++ b/.env.sample @@ -1,7 +1,2 @@ -<<<<<<< HEAD -REACT_APP_API_URL='http://localhost:3000/api/v1/' -======= REACT_APP_API_URL= -REACT_APP_LOCAL_BASE_URL= -REACT_APP_OTHER_BASE_URL= ->>>>>>> 4ae8399... redirect to local login url when not in production env +REACT_APP_BACK_BASE_URL= diff --git a/src/utils/token.ts b/src/utils/token.ts index 17133c6..4a35dc8 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -30,7 +30,11 @@ export function getOauthTokenOrRedirect(): string { return ""; } -const LOGIN_PAGE_URL = `${process.env.REACT_APP_BASE_URL}/auth/google_oauth2` +const appBackBaseUrl = process.env.REACT_APP_BACK_BASE_URL +const LOGIN_PAGE_URL = `${process.env.REACT_APP_BACK_BASE_URL}/auth/google_oauth2` + +console.log('LOGIN_PAGE_URL'); + export function redirectToLoginPage() { window.location.href = `${LOGIN_PAGE_URL}?redirect_to=${window.location.href}`; From db30b7000433a36a7ee759338001fcc28ee770c1 Mon Sep 17 00:00:00 2001 From: Anne-Marie Date: Thu, 6 Aug 2020 14:45:11 +0200 Subject: [PATCH 5/7] refacto --- src/utils/token.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/utils/token.ts b/src/utils/token.ts index 4a35dc8..d580eea 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -30,11 +30,7 @@ export function getOauthTokenOrRedirect(): string { return ""; } -const appBackBaseUrl = process.env.REACT_APP_BACK_BASE_URL -const LOGIN_PAGE_URL = `${process.env.REACT_APP_BACK_BASE_URL}/auth/google_oauth2` - -console.log('LOGIN_PAGE_URL'); - +const LOGIN_PAGE_URL = `${process.env.REACT_APP_BACK_BASE_URL}/auth/google_oauth2`; export function redirectToLoginPage() { window.location.href = `${LOGIN_PAGE_URL}?redirect_to=${window.location.href}`; From 0a7225e38b801b34b0ecee80a94ffaf097d4be85 Mon Sep 17 00:00:00 2001 From: Anne-Marie Date: Tue, 25 Aug 2020 14:59:47 +0200 Subject: [PATCH 6/7] Some refactoring on env var so we have now url distinct from api path --- .env.sample | 2 +- package.json | 2 +- src/index.tsx | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.env.sample b/.env.sample index 359e09b..1db85d3 100644 --- a/.env.sample +++ b/.env.sample @@ -1,2 +1,2 @@ -REACT_APP_API_URL= +REACT_APP_API_PATH= REACT_APP_BACK_BASE_URL= diff --git a/package.json b/package.json index 4c55c36..00d5548 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", - "test:serve": "REACT_APP_API_URL=/api/v1 BROWSER=none yarn start", + "test:serve": "REACT_APP_API_PATH=/api/v1 BROWSER=none yarn start", "cypress:open": "cypress open", "cypress:run": "cypress run --record", "test:ui": " start-server-and-test test:serve 3000 cypress:run" diff --git a/src/index.tsx b/src/index.tsx index 1895969..849dad7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -14,7 +14,10 @@ import * as serviceWorker from "./serviceWorker"; import { Theme } from "./ui/Theme/Theme"; const authToken = getOauthTokenOrRedirect(); -const apiUrl = process.env.REACT_APP_API_URL!; + +const apiPath = process.env.REACT_APP_API_PATH!; + +const apiUrl = `${process.env.REACT_APP_BACK_BASE_URL}${apiPath}`; const httpClient = createHttpClient(apiUrl, authToken); From 1a0e4cd4427264fc8b196b674bced325024ac277 Mon Sep 17 00:00:00 2001 From: Arnaud Doucerain Date: Sun, 15 Nov 2020 10:44:18 +0100 Subject: [PATCH 7/7] Update README & .env.sample to help developers --- .env.sample | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.sample b/.env.sample index 1db85d3..568b2c1 100644 --- a/.env.sample +++ b/.env.sample @@ -1,2 +1,2 @@ -REACT_APP_API_PATH= -REACT_APP_BACK_BASE_URL= +REACT_APP_API_PATH=/api/v1 +REACT_APP_BACK_BASE_URL=http://localhost:3001 diff --git a/README.md b/README.md index 32e0b09..3510d80 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo # Run back server -- App needs api running: [moss back server url](https://github.com/octo-wam/moss-back) +- App needs API running: [moss back server url](https://github.com/octo-wam/moss-back) (update `.env` with accurate REACT_APP_API_PATH and REACT_APP_BACK_BASE_URL) ## Available Scripts