Add config documentation, and better types
This commit is contained in:
parent
9bf1b6f928
commit
0e478f4c20
2 changed files with 27 additions and 10 deletions
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Add table
Reference in a new issue