From c189b25de7a49ef8fff97986a6526ab298ab3339 Mon Sep 17 00:00:00 2001 From: if1live Date: Tue, 3 Oct 2023 14:39:52 +0900 Subject: [PATCH] =?UTF-8?q?process.env=EB=A5=BC=20=EC=A7=81=EC=A0=91=20?= =?UTF-8?q?=EC=B0=B8=EC=A1=B0=ED=95=98=EC=A7=80=20=EC=95=8A=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/settings.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index e1d84f5..0e18b71 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -22,11 +22,18 @@ const dirname = url.fileURLToPath(new URL(".", import.meta.url)); export const rootPath = path.join(dirname, ".."); export const viewPath = path.join(rootPath, "views"); -const parse = (prefix: string): ProviderInput => { - const label = process.env[`${prefix}_LABEL`]!; - const type = process.env[`${prefix}_TYPE`]!; - const arg_1 = process.env[`${prefix}_ARG_1`]; - const arg_2 = process.env[`${prefix}_ARG_2`]; +const parse = ( + env: Record, + prefix: string, +): ProviderInput => { + const label = env[`${prefix}_LABEL`]; + const type = env[`${prefix}_TYPE`]; + const arg_1 = env[`${prefix}_ARG_1`]; + const arg_2 = env[`${prefix}_ARG_2`]; + const arg_3 = env[`${prefix}_ARG_3`]; + + assert(label, "label is empty"); + switch (type) { case "mysql": { assert(arg_1, "endpoint is empty"); @@ -69,8 +76,8 @@ const parse = (prefix: string): ProviderInput => { // TODO: label, type, args로 알아서 대응하기. env 뜯으면 얻을 수 있다. export const providerInputs: ProviderInput[] = [ - parse("AYANE_PLANETSCALE"), - parse("AYANE_SUPABASE"), - parse("AYANE_REDISLAB"), - parse("AYANE_UPSTASH_REDIS"), + parse(process.env, "AYANE_PLANETSCALE"), + parse(process.env, "AYANE_SUPABASE"), + parse(process.env, "AYANE_REDISLAB"), + parse(process.env, "AYANE_UPSTASH_REDIS"), ];