feat: MongoDB 仅保留连接状态 + 站点级密码门禁(WEBPASSWORD)

This commit is contained in:
ice-a
2026-10-16 19:11:19 +08:00
parent 090a7254e0
commit 9b3113bc33
9 changed files with 150 additions and 23 deletions
+17
View File
@@ -0,0 +1,17 @@
// 校验站点访问密码(来自环境变量 WEBPASSWORD),成功后写入 HTTP-only cookie
export default defineEventHandler(async (event) => {
const password = process.env.WEBPASSWORD
if (!password) return { enabled: false }
const body = await readBody<{ password?: string }>(event)
if (body.password === password) {
setCookie(event, 'web_unlock', '1', {
httpOnly: true,
sameSite: 'lax',
path: '/',
maxAge: 60 * 60 * 24 * 30
})
return { ok: true }
}
throw createError({ statusCode: 401, statusMessage: 'invalid password' })
})