From 8621ddb6a27b3f57dda2e0d96929301266daf08a Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Thu, 2 Jul 2020 16:52:58 +0100 Subject: [PATCH] Extract backend URLs into environment variables (#1772) (#1848) --- .env | 4 ++++ src/data/index.ts | 8 ++++---- src/global.d.ts | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..e36b6819 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +REACT_APP_BACKEND_V1_GET_URL=https://json.excalidraw.com/api/v1/ +REACT_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/ +REACT_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/ +REACT_APP_SOCKET_SERVER_URL=https://excalidraw-socket.herokuapp.com diff --git a/src/data/index.ts b/src/data/index.ts index f9c3bec1..129f6b43 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -24,12 +24,12 @@ export { loadFromBlob } from "./blob"; export { saveAsJSON, loadFromJSON } from "./json"; export { saveToLocalStorage } from "./localStorage"; -const BACKEND_GET = "https://json.excalidraw.com/api/v1/"; +const BACKEND_GET = process.env.REACT_APP_BACKEND_V1_GET_URL; -const BACKEND_V2_POST = "https://json.excalidraw.com/api/v2/post/"; -const BACKEND_V2_GET = "https://json.excalidraw.com/api/v2/"; +const BACKEND_V2_POST = process.env.REACT_APP_BACKEND_V2_POST_URL; +const BACKEND_V2_GET = process.env.REACT_APP_BACKEND_V2_GET_URL; -export const SOCKET_SERVER = "https://excalidraw-socket.herokuapp.com"; +export const SOCKET_SERVER = process.env.REACT_APP_SOCKET_SERVER_URL; export type EncryptedData = { data: ArrayBuffer; diff --git a/src/global.d.ts b/src/global.d.ts index f1ce450c..efee9576 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -13,6 +13,16 @@ interface Window { __EXCALIDRAW_SHA__: string; } +// https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.ts +declare namespace NodeJS { + interface ProcessEnv { + readonly REACT_APP_BACKEND_V1_GET_URL: string; + readonly REACT_APP_BACKEND_V2_GET_URL: string; + readonly REACT_APP_BACKEND_V2_POST_URL: string; + readonly REACT_APP_SOCKET_SERVER_URL: string; + } +} + interface Clipboard extends EventTarget { write(data: any[]): Promise; }