service status on atproto

refactor(proxy): move config stuff into its own file

ptr.pet 92c567b1 982d5ceb

verified
+28 -26
+27
proxy/src/config.ts
··· 1 + import { isDid, type AtprotoDid } from "@atcute/lexicons/syntax"; 2 + import { env } from "process"; 3 + 4 + interface Config { 5 + repoDid: AtprotoDid; 6 + appPass: string; 7 + } 8 + 9 + const getConfig = (prefix: string): Config => { 10 + const get = <Value>( 11 + name: string, 12 + check: (value: unknown) => boolean = (value) => 13 + typeof value !== "undefined", 14 + ): Value => { 15 + const value = env[`${prefix}${name}`]; 16 + if (check(value)) { 17 + return value as Value; 18 + } 19 + throw `config key ${name} is invalid`; 20 + }; 21 + return { 22 + repoDid: get("REPO_DID", isDid), 23 + appPass: get("APP_PASSWORD"), 24 + }; 25 + }; 26 + 27 + export const config = getConfig("BAROMETER_");
+1 -26
proxy/src/index.ts
··· 11 11 WebDidDocumentResolver, 12 12 } from "@atcute/identity-resolver"; 13 13 import { isDid, type AtprotoDid } from "@atcute/lexicons/syntax"; 14 - import { env } from "process"; 14 + import { config } from "./config"; 15 15 import type {} from "@atcute/atproto"; 16 16 import {} from "barometer-lexicon"; 17 17 import { SystemsGazeBarometerState } from "barometer-lexicon"; 18 18 import { now as generateTid } from "@atcute/tid"; 19 19 import { is, safeParse } from "@atcute/lexicons"; 20 - 21 - interface Config { 22 - repoDid: AtprotoDid; 23 - appPass: string; 24 - } 25 - 26 - const getConfig = (prefix: string): Config => { 27 - const get = <Value>( 28 - name: string, 29 - check: (value: unknown) => boolean = (value) => 30 - typeof value !== "undefined", 31 - ): Value => { 32 - const value = env[`${prefix}${name}`]; 33 - if (check(value)) { 34 - return value as Value; 35 - } 36 - throw `config key ${name} is invalid`; 37 - }; 38 - return { 39 - repoDid: get("REPO_DID", isDid), 40 - appPass: get("APP_PASSWORD"), 41 - }; 42 - }; 43 - 44 - const config = getConfig("BAROMETER_"); 45 20 46 21 const docResolver = new CompositeDidDocumentResolver({ 47 22 methods: {