fea: 检查本地环境
This commit is contained in:
1 parent
b34def5f32
commit
3a81a927e4
3 files changed
+25
No files matched your search
@@ -1,4 +1,6 @@
|
|||||||
export class responseStr {
|
export class responseStr {
|
||||||
|
static ENV_ADMINNAME_INVALID = "[env variable]: 管理员用户名未设置: admin_name"
|
||||||
|
static ENV_ADMINPASSWD_INVALID = "[env variable]: 管理员密码未设置: admin_passwd"
|
||||||
static REQ_PARAM_ERR = '请求参数错误'
|
static REQ_PARAM_ERR = '请求参数错误'
|
||||||
|
|
||||||
static ADMIN_INVALID = "管理员验证失败"
|
static ADMIN_INVALID = "管理员验证失败"
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { validator } from "hono/validator";
|
|||||||
import { checkAdmin } from "./utils/admin";
|
import { checkAdmin } from "./utils/admin";
|
||||||
import { addUser, checkUser, getAllUser } from "./utils/user";
|
import { addUser, checkUser, getAllUser } from "./utils/user";
|
||||||
import { responseStr } from "./const/response_str";
|
import { responseStr } from "./const/response_str";
|
||||||
|
import { checkEnv } from "./utils/env";
|
||||||
|
|
||||||
|
checkEnv()
|
||||||
const appTmp = new Hono()
|
const appTmp = new Hono()
|
||||||
const app = appTmp.basePath("/auth")
|
const app = appTmp.basePath("/auth")
|
||||||
const db = new SQL({
|
const db = new SQL({
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user