From 01e6cb1075e3fdfc37b0ae5175251349ac932e98 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Fri, 24 Jan 2025 15:00:50 +0800 Subject: [PATCH] feat: |worker| health_check add JWT_SECRET and DOMAINS (#573) --- worker/src/worker.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/worker/src/worker.ts b/worker/src/worker.ts index 260554b8..653f8d73 100644 --- a/worker/src/worker.ts +++ b/worker/src/worker.ts @@ -12,7 +12,7 @@ import { api as telegramApi } from './telegram_api' import { email } from './email'; import { scheduled } from './scheduled'; -import { getAdminPasswords, getPasswords, getBooleanValue } from './utils'; +import { getAdminPasswords, getPasswords, getBooleanValue, getStringArray } from './utils'; import { HonoCustomType, UserPayload } from './types'; const app = new Hono() @@ -210,14 +210,21 @@ app.route('/', adminApi) app.route('/', apiSendMail) app.route('/', telegramApi) -app.get('/', async c => { - if (!c.env.DB) { return c.text("DB is not available", 400); } +const health_check = async (c: Context) => { + if (!c.env.DB) { + return c.text("DB is not available", 400); + } + if (!c.env.JWT_SECRET) { + return c.text("JWT_SECRET is not set", 400); + } + if (getStringArray(c.env.DOMAINS).length === 0) { + return c.text("DOMAINS is not set", 400); + } return c.text("OK"); -}) -app.get('/health_check', async c => { - if (!c.env.DB) { return c.text("DB is not available", 400); } - return c.text("OK"); -}) +} + +app.get('/', health_check) +app.get('/health_check', health_check) app.all('/*', async c => c.text("Not Found", 404))