From 3a81a927e4b7657b65804098a5fa01064778c070 Mon Sep 17 00:00:00 2001 From: CancerAi Date: Sun, 11 Oct 2026 22:41:04 +0800 Subject: [PATCH] =?UTF-8?q?fea:=20=E6=A3=80=E6=9F=A5=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/const/response_str.ts | 2 ++ src/index.ts | 2 ++ src/utils/env.ts | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/utils/env.ts diff --git a/src/const/response_str.ts b/src/const/response_str.ts index e75db79..8d3efd7 100644 --- a/src/const/response_str.ts +++ b/src/const/response_str.ts @@ -1,4 +1,6 @@ export class responseStr { + static ENV_ADMINNAME_INVALID = "[env variable]: 管理员用户名未设置: admin_name" + static ENV_ADMINPASSWD_INVALID = "[env variable]: 管理员密码未设置: admin_passwd" static REQ_PARAM_ERR = '请求参数错误' static ADMIN_INVALID = "管理员验证失败" diff --git a/src/index.ts b/src/index.ts index aeb2a5a..e5116e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,9 @@ import { validator } from "hono/validator"; import { checkAdmin } from "./utils/admin"; import { addUser, checkUser, getAllUser } from "./utils/user"; import { responseStr } from "./const/response_str"; +import { checkEnv } from "./utils/env"; +checkEnv() const appTmp = new Hono() const app = appTmp.basePath("/auth") const db = new SQL({ diff --git a/src/utils/env.ts b/src/utils/env.ts new file mode 100644 index 0000000..f0ec469 --- /dev/null +++ b/src/utils/env.ts @@ -0,0 +1,21 @@ +import { responseStr } from "../const/response_str"; + +export function checkEnv() { + const adminName = Bun.env.admin_name + const adminPasswd = Bun.env.admin_passwd + let isRight = true + + if (adminName == undefined) { + console.log(responseStr.ENV_ADMINNAME_INVALID); + isRight = false + } + + if (adminPasswd == undefined) { + console.log(responseStr.ENV_ADMINPASSWD_INVALID); + isRight = false + } + + if (!isRight) { + process.exit(1) + } +} \ No newline at end of file