Skip to content

Commit

Permalink
fix:处理OPTIONS请求
Browse files Browse the repository at this point in the history
  • Loading branch information
x-dr committed Feb 7, 2024
1 parent 660a81d commit 05088cf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion functions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ function generateRandomString(length) {

return result;
}
export async function onRequestPost(context) {

export async function onRequest(context) {
if (context.request.method === 'OPTIONS') {
return new Response(null, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '86400', // 24小时
},
});
}
// export async function onRequestPost(context) {
const { request, env } = context;
const originurl = new URL(request.url);
const clientIP = request.headers.get("x-forwarded-for") || request.headers.get("clientIP");
Expand Down

0 comments on commit 05088cf

Please sign in to comment.