From eab1767a4ec7f814148a7e0b8ff788775b14f12f Mon Sep 17 00:00:00 2001 From: Vinlic Date: Fri, 5 Apr 2024 01:06:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=AC=A2=E8=BF=8E=E9=A1=B5?= =?UTF-8?q?=E5=92=8C=E9=94=99=E8=AF=AF=E8=AF=B7=E6=B1=82=E5=BC=95=E5=AF=BC?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E5=B0=8F=E7=99=BD=E6=9B=B4=E5=8F=8B=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/welcome.html | 10 ++++++++++ src/api/routes/index.ts | 16 ++++++++++++++++ src/lib/response/FailureBody.ts | 2 +- src/lib/server.ts | 6 +++++- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 public/welcome.html diff --git a/public/welcome.html b/public/welcome.html new file mode 100644 index 0000000..fd7baf4 --- /dev/null +++ b/public/welcome.html @@ -0,0 +1,10 @@ + + + + + 🚀 服务已启动 + + +

qwen-free-api已启动!
请通过LobeChat / NextChat / Dify等客户端或OpenAI SDK接入!

+ + \ No newline at end of file diff --git a/src/api/routes/index.ts b/src/api/routes/index.ts index 814a995..706525a 100644 --- a/src/api/routes/index.ts +++ b/src/api/routes/index.ts @@ -1,8 +1,24 @@ +import fs from 'fs-extra'; + +import Response from '@/lib/response/Response.ts'; import chat from "./chat.ts"; import images from "./images.ts"; import ping from "./ping.ts"; export default [ + { + get: { + '/': async () => { + const content = await fs.readFile('public/welcome.html'); + return new Response(content, { + type: 'html', + headers: { + Expires: '-1' + } + }); + } + } + }, chat, images, ping diff --git a/src/lib/response/FailureBody.ts b/src/lib/response/FailureBody.ts index 1f66417..69364d2 100644 --- a/src/lib/response/FailureBody.ts +++ b/src/lib/response/FailureBody.ts @@ -15,7 +15,7 @@ export default class FailureBody extends Body { else if(error instanceof APIException || error instanceof Exception) ({ errcode, errmsg, data, httpStatusCode } = error); else if(_.isError(error)) - error = new Exception(EX.SYSTEM_ERROR, error.message); + ({ errcode, errmsg, data, httpStatusCode } = new Exception(EX.SYSTEM_ERROR, error.message)); super({ code: errcode || -1, message: errmsg || 'Internal error', diff --git a/src/lib/server.ts b/src/lib/server.ts index a8645e8..8c0e46a 100644 --- a/src/lib/server.ts +++ b/src/lib/server.ts @@ -73,7 +73,11 @@ class Server { this.app.use((ctx: any) => { const request = new Request(ctx); logger.debug(`-> ${ctx.request.method} ${ctx.request.url} request is not supported - ${request.remoteIP || "unknown"}`); - const failureBody = new FailureBody(new Exception(EX.SYSTEM_NOT_ROUTE_MATCHING, "Request is not supported")); + // const failureBody = new FailureBody(new Exception(EX.SYSTEM_NOT_ROUTE_MATCHING, "Request is not supported")); + // const response = new Response(failureBody); + const message = `[请求有误]: 正确请求为 POST -> /v1/chat/completions,当前请求为 ${ctx.request.method} -> ${ctx.request.url} 请纠正`; + logger.warn(message); + const failureBody = new FailureBody(new Error(message)); const response = new Response(failureBody); response.injectTo(ctx); if(config.system.requestLog)