async def on_fetch(request, env):
if request.method == "OPTIONS":
# Handle preflight requests
headers = Headers.new({
"Access-Control-Allow-Origin": "*", # Allow requests from any origin
"Access-Control-Allow-Methods": "GET, POST, OPTIONS", # Specify allowed methods
"Access-Control-Allow-Headers": "Content-Type", # Specify allowed headers
})
return Response.new(None, status=204, headers=headers)
else:
# Handle other requests
payload = json.dumps({ "business": random.choice(business), "concept": random.choice(concepts) }, sort_keys=True)
headers = Headers.new({
"content-type": "application/json",
"Access-Control-Allow-Origin": "*",
})
return Response.new(payload, headers=headers)
async def on_fetch(request, env):
if request.method == "OPTIONS":
# Handle preflight requests
headers = Headers.new({
"Access-Control-Allow-Origin": "*", # Allow requests from any origin
"Access-Control-Allow-Methods": "GET, POST, OPTIONS", # Specify allowed methods
"Access-Control-Allow-Headers": "Content-Type", # Specify allowed headers
})
return Response.new(None, status=204, headers=headers)
else:
# Handle other requests
payload = json.dumps({ "business": random.choice(business), "concept": random.choice(concepts) }, sort_keys=True)
headers = Headers.new({
"content-type": "application/json",
"Access-Control-Allow-Origin": "*",
})
return Response.new(payload, headers=headers)