Merge pull request #743 from robintown/config

Improve config documentation and setup
This commit is contained in:
Robin 2022-11-11 08:19:40 -05:00 committed by GitHub
commit 6ef41b924d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 30 deletions

View file

@ -1,5 +1,5 @@
#### ####
# App Config # Build-time app config
# Environment files are documented here: # Environment files are documented here:
# https://vitejs.dev/guide/env-and-mode.html#env-files # https://vitejs.dev/guide/env-and-mode.html#env-files
#### ####
@ -8,12 +8,6 @@
# VITE_DEFAULT_HOMESERVER=http://localhost:8008 # VITE_DEFAULT_HOMESERVER=http://localhost:8008
# VITE_FALLBACK_STUN_ALLOWED=false # 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_CUSTOM_THEME=true
# VITE_THEME_ACCENT=#0dbd8b # VITE_THEME_ACCENT=#0dbd8b
# VITE_THEME_ACCENT_20=#0dbd8b33 # VITE_THEME_ACCENT_20=#0dbd8b33

2
.gitignore vendored
View file

@ -5,4 +5,4 @@ dist
dist-ssr dist-ssr
*.local *.local
.idea/ .idea/
config.json public/config.json

View file

@ -16,9 +16,10 @@ git clone https://github.com/vector-im/element-call.git
cd element-call cd element-call
yarn yarn
cp .env.example .env 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: Next, build the project:
@ -59,6 +60,7 @@ cd element-call
yarn yarn
yarn link matrix-js-sdk yarn link matrix-js-sdk
cp .env.example .env 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. 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 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 ## Translation

View file

@ -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": { "rageshake": {
"submit_url": "http://localhost:9110/api/submit" "submit_url": "https://element.io/bugreports/submit"
} }
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { DEFAULT_CONFIG, IConfigOptions } from "./ConfigOptions"; import { DEFAULT_CONFIG, ConfigOptions, ResolvedConfigOptions } from "./ConfigOptions";
export class Config { export class Config {
private static internalInstance: Config; private static internalInstance: Config;
@ -37,13 +37,13 @@ export class Config {
return Config.internalInstance.initPromise; return Config.internalInstance.initPromise;
} }
public config: IConfigOptions; public config: ResolvedConfigOptions;
private initPromise: Promise<void>; private initPromise: Promise<void>;
} }
async function downloadConfig( async function downloadConfig(
configJsonFilename: string configJsonFilename: string
): Promise<IConfigOptions> { ): Promise<ConfigOptions> {
const url = new URL(configJsonFilename, window.location.href); const url = new URL(configJsonFilename, window.location.href);
url.searchParams.set("cachebuster", Date.now().toString()); url.searchParams.set("cachebuster", Date.now().toString());
const res = await fetch(url, { const res = await fetch(url, {
@ -51,14 +51,12 @@ async function downloadConfig(
method: "GET", 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. // 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: // 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. // 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();
}
} }

View file

@ -1,18 +1,37 @@
export interface IConfigOptions { export interface ConfigOptions {
/**
* The Posthog endpoint to which analytics data will be sent.
*/
posthog?: { posthog?: {
api_key: string; api_key: string;
api_host: string; api_host: string;
}; };
/**
* The Sentry endpoint to which crash data will be sent.
*/
sentry?: { sentry?: {
DSN: string; DSN: string;
environment: string; environment: string;
}; };
/**
* The rageshake server to which feedback and debug logs will be sent.
*/
rageshake?: { rageshake?: {
submit_url: string; 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" }, sentry: { DSN: "", environment: "production" },
rageshake: { rageshake: {
submit_url: "https://element.io/bugreports/submit", submit_url: "https://element.io/bugreports/submit",