import { authMiddleware } from "../utils/auth.js"; | |
export const onRequest = async (context: RouteContext): Promise<Response> => { | |
const request = context.request; | |
const env = context.env as Env; | |
const authResponse = await authMiddleware(request, env); | |
if (authResponse) { | |
return authResponse; | |
} | |
try { | |
if (request.method === 'GET') { | |
} | |
if (request.method === 'POST') { | |
} | |
if (request.method === 'PUT') { | |
} | |
if (request.method === 'DELETE') { | |
} | |
// 不支持的请求方法 | |
return new Response(JSON.stringify({ error: '不支持的请求方法' }), { | |
status: 405, | |
headers: { 'Content-Type': 'application/json' } | |
}); | |
} catch (error) { | |
return new Response(JSON.stringify({ error: '服务器内部错误' }), { | |
status: 500, | |
headers: { 'Content-Type': 'application/json' } | |
}); | |
} | |
}; |