Skip to content

Commit b5aa4ab

Browse files
committed
Workaround to allow OPTIONS request always.
This is necessary (or at least for now I don't know any better) because the `OPTIONS` request does not carry the api key header and thus can not be checked against.
1 parent 10487af commit b5aa4ab

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ async function handleRequest(request) {
244244
case '/':
245245
return homeRequest(request);
246246
default: {
247+
// Not 100% sure if this is a good idea…
248+
// Right now all OPTIONS requests are just simply replied to because otherwise they fail.
249+
// This is necessary because apparently, OPTIONS requests do not carry the `x-cors-proxy-api-key` header so this can not be authorized.
250+
if (request.method === 'OPTIONS') {
251+
return new Response(null, {
252+
headers: fix(new Headers(), request, true),
253+
status: 200,
254+
statusText: 'OK',
255+
});
256+
}
257+
247258
// The "x-cors-proxy-api-key" header is sent when authenticated.
248259
if (request.headers.has('x-cors-proxy-api-key')) {
249260
// Throws exception when authorization fails.

0 commit comments

Comments
 (0)