forked from ubiquity/work.ubq.fi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d038a0b
commit 7766a20
Showing
2 changed files
with
34 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,43 @@ | ||
import { Context } from "./types"; | ||
|
||
export const corsHeaders = { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET", | ||
"Access-Control-Allow-Headers": "Content-Type", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET", | ||
"Access-Control-Allow-Headers": "Content-Type", | ||
}; | ||
|
||
export async function onRequest(ctx: Context): Promise<Response> { | ||
const { request, env } = ctx; | ||
console.log("Request received:", request.method, request.url); | ||
console.log("Environment", env); | ||
const url = new URL(request.url); | ||
const { request, env } = ctx; | ||
console.log("Request received:", request.method, request.url); | ||
console.log("Environment", env); | ||
const url = new URL(request.url); | ||
|
||
try { | ||
switch (request.method) { | ||
|
||
case "GET": | ||
if (url.searchParams.has("key")) { | ||
const key = url.searchParams.get("key") as string; | ||
return new Response("GET request with key: " + key + JSON.stringify(env), { | ||
headers: corsHeaders, | ||
status: 200, | ||
}); | ||
} | ||
return new Response("GET request", { | ||
headers: corsHeaders, | ||
status: 200, | ||
}); | ||
|
||
default: | ||
return new Response("Method Not Allowed", { | ||
headers: corsHeaders, | ||
status: 405, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error("Error processing request:", error); | ||
return new Response("Internal Server Error", { | ||
try { | ||
switch (request.method) { | ||
case "GET": | ||
if (url.searchParams.has("key")) { | ||
const key = url.searchParams.get("key") as string; | ||
return new Response("GET request with key: " + key + JSON.stringify(env), { | ||
headers: corsHeaders, | ||
status: 500, | ||
status: 200, | ||
}); | ||
} | ||
return new Response("GET request", { | ||
headers: corsHeaders, | ||
status: 200, | ||
}); | ||
} | ||
|
||
|
||
} | ||
default: | ||
return new Response("Method Not Allowed", { | ||
headers: corsHeaders, | ||
status: 405, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error("Error processing request:", error); | ||
return new Response("Internal Server Error", { | ||
headers: corsHeaders, | ||
status: 500, | ||
}); | ||
} | ||
} |