From 856ecda262acc2900493068a1a95b03698f837ea Mon Sep 17 00:00:00 2001 From: OTAKE Haruaki Date: Thu, 8 Aug 2024 15:06:21 +0900 Subject: [PATCH 1/4] fix: append `access-control-max-age` header to preflight response --- src/utils/cors/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/cors/utils.ts b/src/utils/cors/utils.ts index b4900c63..2465d365 100644 --- a/src/utils/cors/utils.ts +++ b/src/utils/cors/utils.ts @@ -209,6 +209,7 @@ export function appendCorsPreflightHeaders( appendHeaders(event, createExposeHeaders(options)); appendHeaders(event, createMethodsHeaders(options)); appendHeaders(event, createAllowHeaderHeaders(event, options)); + appendHeaders(event, createMaxAgeHeader(options)); } /** From 00b8e87e8efbbccdfd8eb7f1e80c822ec3fe6244 Mon Sep 17 00:00:00 2001 From: OTAKE Haruaki Date: Thu, 8 Aug 2024 15:38:38 +0900 Subject: [PATCH 2/4] fix: fix header types --- src/utils/cors/types.ts | 2 +- src/utils/cors/utils.ts | 2 +- test/cors.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/cors/types.ts b/src/utils/cors/types.ts index 46c5e45b..75ab3d29 100644 --- a/src/utils/cors/types.ts +++ b/src/utils/cors/types.ts @@ -64,7 +64,7 @@ export type H3AccessControlExposeHeadersHeader = export type H3AccessControlMaxAgeHeader = | { - "access-control-max-age": string; + "access-control-max-age": number; } | H3EmptyHeader; diff --git a/src/utils/cors/utils.ts b/src/utils/cors/utils.ts index 2465d365..6a7c3959 100644 --- a/src/utils/cors/utils.ts +++ b/src/utils/cors/utils.ts @@ -191,7 +191,7 @@ export function createMaxAgeHeader( const { maxAge } = options; if (maxAge) { - return { "access-control-max-age": maxAge }; + return { "access-control-max-age": Number.parseInt(maxAge, 10) }; } return {}; diff --git a/test/cors.test.ts b/test/cors.test.ts index cf1dba3c..e471e8c8 100644 --- a/test/cors.test.ts +++ b/test/cors.test.ts @@ -476,10 +476,10 @@ describe("createMaxAgeHeader", () => { }; expect(createMaxAgeHeader(options1)).toEqual({ - "access-control-max-age": "12345", + "access-control-max-age": 12_345, }); expect(createMaxAgeHeader(options2)).toEqual({ - "access-control-max-age": "0", + "access-control-max-age": 0, }); }); }); From 3b69ab1aa8a48b6e7ffd9bd5db98ca9714655805 Mon Sep 17 00:00:00 2001 From: OTAKE Haruaki Date: Thu, 8 Aug 2024 15:50:37 +0900 Subject: [PATCH 3/4] Revert "fix: fix header types" This reverts commit 00b8e87e8efbbccdfd8eb7f1e80c822ec3fe6244. --- src/utils/cors/types.ts | 2 +- src/utils/cors/utils.ts | 2 +- test/cors.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/cors/types.ts b/src/utils/cors/types.ts index 75ab3d29..46c5e45b 100644 --- a/src/utils/cors/types.ts +++ b/src/utils/cors/types.ts @@ -64,7 +64,7 @@ export type H3AccessControlExposeHeadersHeader = export type H3AccessControlMaxAgeHeader = | { - "access-control-max-age": number; + "access-control-max-age": string; } | H3EmptyHeader; diff --git a/src/utils/cors/utils.ts b/src/utils/cors/utils.ts index 6a7c3959..2465d365 100644 --- a/src/utils/cors/utils.ts +++ b/src/utils/cors/utils.ts @@ -191,7 +191,7 @@ export function createMaxAgeHeader( const { maxAge } = options; if (maxAge) { - return { "access-control-max-age": Number.parseInt(maxAge, 10) }; + return { "access-control-max-age": maxAge }; } return {}; diff --git a/test/cors.test.ts b/test/cors.test.ts index e471e8c8..cf1dba3c 100644 --- a/test/cors.test.ts +++ b/test/cors.test.ts @@ -476,10 +476,10 @@ describe("createMaxAgeHeader", () => { }; expect(createMaxAgeHeader(options1)).toEqual({ - "access-control-max-age": 12_345, + "access-control-max-age": "12345", }); expect(createMaxAgeHeader(options2)).toEqual({ - "access-control-max-age": 0, + "access-control-max-age": "0", }); }); }); From 453b3e2b035303e7b39f5b4353241709a4d035ef Mon Sep 17 00:00:00 2001 From: OTAKE Haruaki Date: Thu, 8 Aug 2024 15:52:02 +0900 Subject: [PATCH 4/4] fix: change access-control-max-age type --- src/types/_headers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/_headers.ts b/src/types/_headers.ts index e21e0b06..11979e38 100644 --- a/src/types/_headers.ts +++ b/src/types/_headers.ts @@ -37,7 +37,7 @@ export type TypedHeaders = Partial> & "content-length": number; - "access-control-max-age": number; + "access-control-max-age": AnyString; "retry-after": number;