From 9bf1b6f9285a75d8441b051f3ed2ed572df23b40 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 9 Nov 2022 10:53:00 -0500 Subject: [PATCH 1/4] Remove unused variables from .env.example --- .env.example | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 6da40c18..bd8b6bae 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ #### -# App Config +# Build-time app config # Environment files are documented here: # https://vitejs.dev/guide/env-and-mode.html#env-files #### @@ -8,12 +8,6 @@ # VITE_DEFAULT_HOMESERVER=http://localhost:8008 # VITE_FALLBACK_STUN_ALLOWED=false -# Used for submitting debug logs to an external rageshake server -# VITE_RAGESHAKE_SUBMIT_URL=http://localhost:9110/api/submit - -# The Sentry DSN to use for error reporting. Leave undefined to disable. -# VITE_SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 - # VITE_CUSTOM_THEME=true # VITE_THEME_ACCENT=#0dbd8b # VITE_THEME_ACCENT_20=#0dbd8b33 From 0e478f4c20c8b88350edfeaa35d166f5c94068dd Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 9 Nov 2022 10:53:33 -0500 Subject: [PATCH 2/4] Add config documentation, and better types --- src/config/Config.ts | 14 ++++++-------- src/config/ConfigOptions.ts | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/config/Config.ts b/src/config/Config.ts index 9b3e7183..42d9b1b1 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { DEFAULT_CONFIG, IConfigOptions } from "./ConfigOptions"; +import { DEFAULT_CONFIG, ConfigOptions, ResolvedConfigOptions } from "./ConfigOptions"; export class Config { private static internalInstance: Config; @@ -37,13 +37,13 @@ export class Config { return Config.internalInstance.initPromise; } - public config: IConfigOptions; + public config: ResolvedConfigOptions; private initPromise: Promise; } async function downloadConfig( configJsonFilename: string -): Promise { +): Promise { const url = new URL(configJsonFilename, window.location.href); url.searchParams.set("cachebuster", Date.now().toString()); const res = await fetch(url, { @@ -51,14 +51,12 @@ async function downloadConfig( method: "GET", }); - if (res.status === 404 || res.status === 0) { + if (!res.ok || res.status === 404 || res.status === 0) { // Lack of a config isn't an error, we should just use the defaults. // Also treat a blank config as no config, assuming the status code is 0, because we don't get 404s from file: // URIs so this is the only way we can not fail if the file doesn't exist when loading from a file:// URI. - return {} as IConfigOptions; + return {}; } - if (res.ok) { - return res.json(); - } + return res.json(); } diff --git a/src/config/ConfigOptions.ts b/src/config/ConfigOptions.ts index f32806ea..92dd74fa 100644 --- a/src/config/ConfigOptions.ts +++ b/src/config/ConfigOptions.ts @@ -1,18 +1,37 @@ -export interface IConfigOptions { +export interface ConfigOptions { + /** + * The Posthog endpoint to which analytics data will be sent. + */ posthog?: { api_key: string; api_host: string; }; + /** + * The Sentry endpoint to which crash data will be sent. + */ sentry?: { DSN: string; environment: string; }; + /** + * The rageshake server to which feedback and debug logs will be sent. + */ rageshake?: { submit_url: string; }; } -export const DEFAULT_CONFIG: IConfigOptions = { +export interface ResolvedConfigOptions extends ConfigOptions { + sentry: { + DSN: string; + environment: string; + }; + rageshake: { + submit_url: string; + }; +} + +export const DEFAULT_CONFIG: ResolvedConfigOptions = { sentry: { DSN: "", environment: "production" }, rageshake: { submit_url: "https://element.io/bugreports/submit", From 62988e6b460cf171933b19e3ae4626e5b04fe603 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 9 Nov 2022 10:54:13 -0500 Subject: [PATCH 3/4] Make the sample config usable without any edits --- sample.config.json | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sample.config.json b/sample.config.json index c00e5396..bd05a880 100644 --- a/sample.config.json +++ b/sample.config.json @@ -1,13 +1,5 @@ { - "posthog": { - "api_key": "examplePosthogKey", - "api_host": "https://posthog.com" - }, - "sentry": { - "environment": "main-branch", - "DSN": "https://examplePublicKey@o0.ingest.sentry.io/0" - }, "rageshake": { - "submit_url": "http://localhost:9110/api/submit" + "submit_url": "https://element.io/bugreports/submit" } } From 12079ded4f9d41079541c236174bdcfd1dcd3841 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 9 Nov 2022 10:55:21 -0500 Subject: [PATCH 4/4] Add instructions to put config.json inside public/ --- .gitignore | 2 +- README.md | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f46dc2bc..f6245318 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ dist dist-ssr *.local .idea/ -config.json +public/config.json diff --git a/README.md b/README.md index 9a1d82b9..d666263e 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,10 @@ git clone https://github.com/vector-im/element-call.git cd element-call yarn cp .env.example .env +cp sample.config.json public/config.json ``` -You can now edit the configuration in `.env` to your liking. The most important thing is to set `VITE_DEFAULT_HOMESERVER` to the homeserver that the app should use, such as `https://call.ems.host`. +You can now edit the configuration in `.env` and `public/config.json` to your liking. (See the [configuration](#Configuration) section for details.) The most important thing is to set `VITE_DEFAULT_HOMESERVER` to the homeserver that the app should use, such as `https://call.ems.host`. Next, build the project: @@ -59,6 +60,7 @@ cd element-call yarn yarn link matrix-js-sdk cp .env.example .env +cp sample.config.json public/config.json ``` By default, the app expects you to have [Synapse](https://matrix-org.github.io/synapse/latest/setup/installation.html) installed locally and running on port 8008. If you wish to use another homeserver, you can set it in your `.env` file. @@ -69,9 +71,9 @@ You're now ready to launch the development server: yarn dev ``` -## Config +## Configuration -Configuration options are documented in the `.env` file. +There are currently two different config files. `.env` holds variables that are used at build time, while `public/config.json` holds variables that are used at runtime. Documentation and default values for `public/config.json` can be found in [ConfigOptions.ts](src/config/ConfigOptions.ts). ## Translation