From 9b66cada2bd916989e0a7e99145d439fdd419441 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:06:34 +0100 Subject: [PATCH] feat: support additional headers --- src/next-edge-app/index.ts | 4 ++++ src/next-edge/index.ts | 4 ++++ src/type/create-api-handler-options.ts | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/next-edge-app/index.ts b/src/next-edge-app/index.ts index 4dda803..9c8dc86 100644 --- a/src/next-edge-app/index.ts +++ b/src/next-edge-app/index.ts @@ -79,6 +79,10 @@ export function createApiHandler(options: CreateApiHandlerOptions) { requestHeaders.set("Ory-Base-URL-Rewrite", "false") requestHeaders.set("Ory-No-Custom-Domain-Redirect", "true") + for (const [key, value] of options.additionalHeaders) { + requestHeaders.set(key, value) + } + try { const response = await fetch(url, { method: request.method, diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index 3c9bed9..885125b 100644 --- a/src/next-edge/index.ts +++ b/src/next-edge/index.ts @@ -115,6 +115,10 @@ export function createApiHandler(options: CreateApiHandlerOptions) { headers.set("Ory-Base-URL-Rewrite", "false") headers.set("Ory-No-Custom-Domain-Redirect", "true") + for (const [key, value] of options.additionalHeaders) { + headers.set(key, value) + } + const response = await fetch(url, { method: req.method, headers, diff --git a/src/type/create-api-handler-options.ts b/src/type/create-api-handler-options.ts index 79637d5..52b3507 100644 --- a/src/type/create-api-handler-options.ts +++ b/src/type/create-api-handler-options.ts @@ -39,10 +39,15 @@ export interface CreateApiHandlerOptions { */ fallbackToPlayground?: boolean - /* + /** * Per default headers are filtered to forward only a fixed list. * * If you need to forward additional headers you can use this setting to define them. */ forwardAdditionalHeaders?: string[] + + /** + * Define additional headers to pass to the API. + */ + additionalHeaders?: Headers }