Files
Desktop/app/dns-fallback.main.ts
2026-03-27 10:55:37 -07:00

39 lines
1.1 KiB
TypeScript

// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join } from 'node:path';
import { readFile } from 'node:fs/promises';
import { DNSFallbackSchema } from '../ts/types/DNSFallback.std.js';
import type { DNSFallbackType } from '../ts/types/DNSFallback.std.js';
import { parseUnknown } from '../ts/util/schemas.std.js';
import { getAppRootDir } from '../ts/util/appRootDir.main.js';
import { createLogger } from '../ts/logging/log.std.js';
const log = createLogger('dns-fallback');
let cached: DNSFallbackType | undefined;
export async function getDNSFallback(): Promise<DNSFallbackType> {
if (cached != null) {
return cached;
}
const configPath = join(getAppRootDir(), 'build', 'dns-fallback.json');
let str: string;
try {
str = await readFile(configPath, 'utf8');
} catch (error) {
log.error(
'Warning: build/dns-fallback.json not build, run `npm run build:dns-fallback`'
);
cached = [];
return cached;
}
const json: unknown = JSON.parse(str);
const result = parseUnknown(DNSFallbackSchema, json);
cached = result;
return result;
}