From f583d0b2d44e56af350bced59b7c285380db2e03 Mon Sep 17 00:00:00 2001 From: D8D Developer Date: Wed, 30 Apr 2025 07:00:49 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=80=BB=E8=BE=91=EF=BC=8C=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=9D=E5=A7=8B=E5=8C=96=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?API=20Client=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=B9=B6=E9=9B=86=E6=88=90CORS=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=8F=90=E5=8D=87=E7=B3=BB=E7=BB=9F=E5=8F=AF?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E6=80=A7=E4=B8=8E=E8=B7=A8=E5=9F=9F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app.tsx | 2 +- server/run.ts | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ test.log | 54 --------------------------------- 3 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 server/run.ts delete mode 100644 test.log diff --git a/server/app.tsx b/server/app.tsx index 6a35813..e9f0740 100644 --- a/server/app.tsx +++ b/server/app.tsx @@ -226,7 +226,7 @@ export type WithAuth = typeof withAuth; // 定义模块参数接口 interface ModuleParams { apiClient: APIClient - app: Hono<{ Variables: Variables }> + app: Hono moduleDir: string } diff --git a/server/run.ts b/server/run.ts new file mode 100644 index 0000000..427503b --- /dev/null +++ b/server/run.ts @@ -0,0 +1,81 @@ +// 导入所需模块 +import { Hono } from 'hono' +import { APIClient } from '@d8d-appcontainer/api' +import debug from "debug" +import { cors } from 'hono/cors' + +// 初始化debug实例 +const log = { + app: debug('app:server'), + auth: debug('auth:server'), + api: debug('api:server'), + debug: debug('debug:server') +} + +// 启用所有日志 +Object.values(log).forEach(logger => logger.enabled = true) + +// 初始化 API Client +const getApiClient = async (workspaceKey: string, serverUrl?: string) => { + try { + log.api('正在初始化API Client实例') + + const apiClient = await APIClient.getInstance({ + scope: 'user', + config: { + serverUrl: serverUrl || Deno.env.get('SERVER_URL') || 'https://app-server.d8d.fun', + workspaceKey: workspaceKey, + type: 'http', + } + }) + + log.api('API Client初始化成功') + return apiClient + } catch (error) { + log.api('API Client初始化失败:', error) + throw error + } +} + +// 创建Hono应用实例 +const app = new Hono() + +// 注册CORS中间件 +app.use('/*', cors()) + +// 动态加载并运行模板 +const runTemplate = async () => { + try { + // 创建基础app实例 + const moduleApp = new Hono() + + // 初始化API Client + // 注意:WORKSPACE_KEY 需要在 多八多(www.d8d.fun) 平台注册并开通工作空间后获取 + const workspaceKey = Deno.env.get('WORKSPACE_KEY') || '' + if (!workspaceKey) { + console.warn('未设置WORKSPACE_KEY,请前往 多八多(www.d8d.fun) 注册并开通工作空间以获取密钥') + } + const apiClient = await getApiClient(workspaceKey) + + // 导入模板主模块 + const templateModule = await import('./app.tsx') + + if (templateModule.default) { + // 传入必要参数并初始化应用 + const appInstance = templateModule.default({ + apiClient: apiClient, + app: moduleApp, + moduleDir: './admin-mobile-starter' + }) + + // 启动服务器 + Deno.serve({ port: 8000 }, appInstance.fetch) + console.log('应用已启动,监听端口: 8000') + } + } catch (error) { + console.error('模板加载失败:', error) + } +} + +// 执行模板 +runTemplate() \ No newline at end of file diff --git a/test.log b/test.log deleted file mode 100644 index 253d994..0000000 --- a/test.log +++ /dev/null @@ -1,54 +0,0 @@ -[测试套件] 知识库管理页面测试 (./client/admin/pages_know_info.test.tsx) - -[测试用例] 应正确渲染页面元素 -- 状态: 通过 -- 耗时: 2.000s - -[测试用例] 初始加载表格数据 -- 状态: 通过 -- 耗时: 0.729s - -[测试用例] 搜索表单应正常工作 -- 状态: 通过 -- 耗时: 1.000s - -[测试用例] 表格应加载并显示数据 -- 状态: 通过 -- 耗时: 0.038s - -[测试用例] 应能打开添加文章模态框 -- 状态: 通过 -- 耗时: 0.298s -- 输出内容: -
- 添加知识库文章 -
- -[测试用例] 应能完整添加一篇文章 -- 状态: 通过 -- 耗时: 0.483s -- 输出内容: - -