From daaa220a47aa38795cffdd290ee33aeab858810c Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sun, 18 Jan 2026 02:57:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80HTTP=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=A4=84=E7=90=86=E4=B8=BAANY=E5=B9=B6=E9=9B=86?= =?UTF-8?q?=E4=B8=AD=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将所有HTTP方法处理统一为ANY方法,直接在单个处理器中处理所有请求并返回响应或404错误。 --- src/routes/api/rpc.$.ts | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/routes/api/rpc.$.ts b/src/routes/api/rpc.$.ts index 18fa6f9..de726dc 100644 --- a/src/routes/api/rpc.$.ts +++ b/src/routes/api/rpc.$.ts @@ -43,28 +43,17 @@ const handler = new RPCHandler(router, { ], }) -async function handle({ request }: { request: Request }) { - const { matched, response } = await handler.handle(request, { - prefix: '/api/rpc', - context: {}, - }) - - if (matched) { - return response - } - - return new Response('Not Found', { status: 404 }) -} - export const Route = createFileRoute('/api/rpc/$')({ server: { handlers: { - HEAD: handle, - GET: handle, - POST: handle, - PUT: handle, - PATCH: handle, - DELETE: handle, + ANY: async ({ request }) => { + const { response } = await handler.handle(request, { + prefix: '/api/rpc', + context: {}, + }) + + return response ?? new Response('Not Found', { status: 404 }) + }, }, }, })