mirror of
https://github.com/LLM-Red-Team/qwen-free-api.git
synced 2024-12-23 01:49:20 +08:00
补充欢迎页和错误请求引导,对小白更友好
This commit is contained in:
parent
c259afa34d
commit
eab1767a4e
10
public/welcome.html
Normal file
10
public/welcome.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>🚀 服务已启动</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>qwen-free-api已启动!<br>请通过LobeChat / NextChat / Dify等客户端或OpenAI SDK接入!</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,8 +1,24 @@
|
|||||||
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
|
import Response from '@/lib/response/Response.ts';
|
||||||
import chat from "./chat.ts";
|
import chat from "./chat.ts";
|
||||||
import images from "./images.ts";
|
import images from "./images.ts";
|
||||||
import ping from "./ping.ts";
|
import ping from "./ping.ts";
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
|
{
|
||||||
|
get: {
|
||||||
|
'/': async () => {
|
||||||
|
const content = await fs.readFile('public/welcome.html');
|
||||||
|
return new Response(content, {
|
||||||
|
type: 'html',
|
||||||
|
headers: {
|
||||||
|
Expires: '-1'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
chat,
|
chat,
|
||||||
images,
|
images,
|
||||||
ping
|
ping
|
||||||
|
@ -15,7 +15,7 @@ export default class FailureBody extends Body {
|
|||||||
else if(error instanceof APIException || error instanceof Exception)
|
else if(error instanceof APIException || error instanceof Exception)
|
||||||
({ errcode, errmsg, data, httpStatusCode } = error);
|
({ errcode, errmsg, data, httpStatusCode } = error);
|
||||||
else if(_.isError(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({
|
super({
|
||||||
code: errcode || -1,
|
code: errcode || -1,
|
||||||
message: errmsg || 'Internal error',
|
message: errmsg || 'Internal error',
|
||||||
|
@ -73,7 +73,11 @@ class Server {
|
|||||||
this.app.use((ctx: any) => {
|
this.app.use((ctx: any) => {
|
||||||
const request = new Request(ctx);
|
const request = new Request(ctx);
|
||||||
logger.debug(`-> ${ctx.request.method} ${ctx.request.url} request is not supported - ${request.remoteIP || "unknown"}`);
|
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);
|
const response = new Response(failureBody);
|
||||||
response.injectTo(ctx);
|
response.injectTo(ctx);
|
||||||
if(config.system.requestLog)
|
if(config.system.requestLog)
|
||||||
|
Loading…
Reference in New Issue
Block a user