Skip to content

Commit

Permalink
feat: |worker| health_check add JWT_SECRET and DOMAINS (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamhunter2333 authored Jan 24, 2025
1 parent 814f6fa commit 01e6cb1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions worker/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HonoCustomType>()
Expand Down Expand Up @@ -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); }
return c.text("OK");
})
app.get('/health_check', async c => {
if (!c.env.DB) { return c.text("DB is not available", 400); }
const health_check = async (c: Context<HonoCustomType>) => {
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)
app.get('/health_check', health_check)
app.all('/*', async c => c.text("Not Found", 404))


Expand Down

0 comments on commit 01e6cb1

Please sign in to comment.