Skip to content

Commit 07bd0a0

Browse files
committed
Add cors support
1 parent 9d2b1a4 commit 07bd0a0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/handler.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { imageSync, image_type } from "qr-image";
22

33
export async function handleRequest(req: Request): Promise<Response> {
4+
5+
if (req.method === 'OPTIONS') {
6+
return new Response(null, {
7+
status: 204,
8+
headers: {
9+
'Access-Control-Allow-Methods': 'GET',
10+
'Access-Control-Allow-Origin': '*'
11+
}
12+
});
13+
}
14+
15+
416
try {
517
const url: URL = new URL(req.url);
618
if (req.method !== "GET")
@@ -32,7 +44,7 @@ export async function handleRequest(req: Request): Promise<Response> {
3244
}
3345

3446
const qrCode = imageSync(code, { type, margin: 2, size });
35-
return new Response(qrCode, { headers: { "Content-type": contentType }, status: 200 });
47+
return new Response(qrCode, { headers: { "Content-type": contentType, 'Access-Control-Allow-Origin': '*' }, status: 200 });
3648
} catch (e) {
3749
return new Response(e, { status: 500 });
3850
}

0 commit comments

Comments
 (0)