Skip to content

Commit 24c9fa9

Browse files
authored
Merge pull request #45 from Brayden/bwilmoth/cors-preflight
CORS Preflight
2 parents 782b43e + b292b62 commit 24c9fa9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/cors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const corsHeaders = {
55
'Access-Control-Max-Age': '86400',
66
};
77

8-
export function corsPreflight(request: Request) {
8+
export function corsPreflight(request: Request): Response | undefined {
99
// Handle OPTIONS preflight request first
1010
if (request.method === 'OPTIONS') {
1111
return new Response(null, {

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ export default {
5454
const isWebSocket = request.headers.get("Upgrade") === "websocket";
5555

5656
// Authorize the request with CORS rules before proceeding.
57-
corsPreflight(request);
57+
if (request.method === 'OPTIONS') {
58+
const preflightResponse = corsPreflight(request)
59+
60+
if (preflightResponse) {
61+
return preflightResponse;
62+
}
63+
}
5864

5965
/**
6066
* If the request is a GET request to the /studio endpoint, we can handle the request

0 commit comments

Comments
 (0)