From 97c0c7c0fc6bb02120b49c756cf213884a1b78ed Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Fri, 28 Nov 2025 15:00:31 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20update=20index.ts=20=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DOCKER_MYSQL_CONNECTION.md | 4 ++-- src/index.ts | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/DOCKER_MYSQL_CONNECTION.md b/DOCKER_MYSQL_CONNECTION.md index 120afe7..4ca6aa4 100644 --- a/DOCKER_MYSQL_CONNECTION.md +++ b/DOCKER_MYSQL_CONNECTION.md @@ -40,8 +40,8 @@ FLUSH PRIVILEGES; mysql -u root -p -- 执行以下SQL语句 -CREATE USER 'shop_mallnew'@'%' IDENTIFIED BY 'shop_mallnew'; -GRANT ALL PRIVILEGES ON huawei_shop_mallnew.* TO 'shop_mallnew'@'%'; +CREATE USER 'shop_admin'@'%' IDENTIFIED BY 'shop_admin'; +GRANT ALL PRIVILEGES ON shop_mallnew.* TO 'shop_admin'@'%'; FLUSH PRIVILEGES; ``` diff --git a/src/index.ts b/src/index.ts index a517bf2..9492747 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,11 +2,28 @@ import { Elysia } from 'elysia'; import routes from './routes'; import { config } from 'dotenv'; +import pool from './db'; config(); +// 初始化 Elysia 应用 const app = new Elysia() .use(routes) - .get('/', () => 'SaaS Admin API - Ready for Dify Agent') + // 根路由,返回 API 就绪状态, 用于健康检查, 显示数据库连接状态 + .get('/', async () => { + // 检查数据库连接 + let dbConnected: string; + try { + await pool.getConnection(); + dbConnected = 'connected'; + } catch (err) { + dbConnected = 'disconnected'; + } + return { + message: 'SaaS Admin API - Ready for Dify Agent', + status: 'ready', + database: dbConnected, + }; + }) .listen(process.env.PORT || 8080); console.log(`🦊 Elysia running on http://localhost:${app.server?.port}`); \ No newline at end of file