service status on atproto

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

ptr.pet 92c567b1 982d5ceb

verified
Changed files
+28 -26
proxy
+27
proxy/src/config.ts
···
+
import { isDid, type AtprotoDid } from "@atcute/lexicons/syntax";
+
import { env } from "process";
+
+
interface Config {
+
repoDid: AtprotoDid;
+
appPass: string;
+
}
+
+
const getConfig = (prefix: string): Config => {
+
const get = <Value>(
+
name: string,
+
check: (value: unknown) => boolean = (value) =>
+
typeof value !== "undefined",
+
): Value => {
+
const value = env[`${prefix}${name}`];
+
if (check(value)) {
+
return value as Value;
+
}
+
throw `config key ${name} is invalid`;
+
};
+
return {
+
repoDid: get("REPO_DID", isDid),
+
appPass: get("APP_PASSWORD"),
+
};
+
};
+
+
export const config = getConfig("BAROMETER_");
+1 -26
proxy/src/index.ts
···
WebDidDocumentResolver,
} from "@atcute/identity-resolver";
import { isDid, type AtprotoDid } from "@atcute/lexicons/syntax";
-
import { env } from "process";
+
import { config } from "./config";
import type {} from "@atcute/atproto";
import {} from "barometer-lexicon";
import { SystemsGazeBarometerState } from "barometer-lexicon";
import { now as generateTid } from "@atcute/tid";
import { is, safeParse } from "@atcute/lexicons";
-
-
interface Config {
-
repoDid: AtprotoDid;
-
appPass: string;
-
}
-
-
const getConfig = (prefix: string): Config => {
-
const get = <Value>(
-
name: string,
-
check: (value: unknown) => boolean = (value) =>
-
typeof value !== "undefined",
-
): Value => {
-
const value = env[`${prefix}${name}`];
-
if (check(value)) {
-
return value as Value;
-
}
-
throw `config key ${name} is invalid`;
-
};
-
return {
-
repoDid: get("REPO_DID", isDid),
-
appPass: get("APP_PASSWORD"),
-
};
-
};
-
-
const config = getConfig("BAROMETER_");
const docResolver = new CompositeDidDocumentResolver({
methods: {