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 1/4] 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 } From 18487cb6e054bffdf428daff49e0e08712377eeb Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:10:58 +0100 Subject: [PATCH 2/4] chore: synchronize workspaces --- src/next-edge-app/index.ts | 5 +++-- src/next-edge/index.ts | 5 +++-- src/type/create-api-handler-options.ts | 5 ----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/next-edge-app/index.ts b/src/next-edge-app/index.ts index 9c8dc86..3ee4bb5 100644 --- a/src/next-edge-app/index.ts +++ b/src/next-edge-app/index.ts @@ -79,8 +79,9 @@ 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) + // Only effective in CI. + if (process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) { + requestHeaders.set(process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) } try { diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index 885125b..167aefe 100644 --- a/src/next-edge/index.ts +++ b/src/next-edge/index.ts @@ -115,8 +115,9 @@ 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) + // Only effective in CI. + if (process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) { + headers.set(process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) } const response = await fetch(url, { diff --git a/src/type/create-api-handler-options.ts b/src/type/create-api-handler-options.ts index 52b3507..15e5980 100644 --- a/src/type/create-api-handler-options.ts +++ b/src/type/create-api-handler-options.ts @@ -45,9 +45,4 @@ export interface CreateApiHandlerOptions { * 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 } From a23b8b7a9b7ff86abd6e02c21196c732a067c28a Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:11:54 +0100 Subject: [PATCH 3/4] chore: synchronize workspaces --- src/next-edge-app/index.ts | 10 ++++++++-- src/next-edge/index.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/next-edge-app/index.ts b/src/next-edge-app/index.ts index 3ee4bb5..3e770d4 100644 --- a/src/next-edge-app/index.ts +++ b/src/next-edge-app/index.ts @@ -80,8 +80,14 @@ export function createApiHandler(options: CreateApiHandlerOptions) { requestHeaders.set("Ory-No-Custom-Domain-Redirect", "true") // Only effective in CI. - if (process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) { - requestHeaders.set(process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) + if ( + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY + ) { + requestHeaders.set( + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY, + ) } try { diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index 167aefe..c336dfa 100644 --- a/src/next-edge/index.ts +++ b/src/next-edge/index.ts @@ -116,8 +116,14 @@ export function createApiHandler(options: CreateApiHandlerOptions) { headers.set("Ory-No-Custom-Domain-Redirect", "true") // Only effective in CI. - if (process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) { - headers.set(process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY) + if ( + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY + ) { + headers.set( + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, + process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY, + ) } const response = await fetch(url, { From 2dd664ca26599e528ea88201a4d0c40aa6c07310 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:12:39 +0100 Subject: [PATCH 4/4] chore: synchronize workspaces --- src/next-edge-app/index.ts | 8 ++++---- src/next-edge/index.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/next-edge-app/index.ts b/src/next-edge-app/index.ts index 3e770d4..8f99fd7 100644 --- a/src/next-edge-app/index.ts +++ b/src/next-edge-app/index.ts @@ -81,12 +81,12 @@ export function createApiHandler(options: CreateApiHandlerOptions) { // Only effective in CI. if ( - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY + process.env.ORY_CI_RATE_LIMIT_HEADER && + process.env.ORY_CI_RATE_LIMIT_HEADER_VALUE ) { requestHeaders.set( - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY, + process.env.ORY_CI_RATE_LIMIT_HEADER, + process.env.ORY_CI_RATE_LIMIT_HEADER_VALUE, ) } diff --git a/src/next-edge/index.ts b/src/next-edge/index.ts index c336dfa..fee5806 100644 --- a/src/next-edge/index.ts +++ b/src/next-edge/index.ts @@ -117,12 +117,12 @@ export function createApiHandler(options: CreateApiHandlerOptions) { // Only effective in CI. if ( - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER && - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY + process.env.ORY_CI_RATE_LIMIT_HEADER && + process.env.ORY_CI_RATE_LIMIT_HEADER_VALUE ) { headers.set( - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_HEADER, - process.env.ORY_NETWORK_STAGING_RATE_LIMIT_KEY, + process.env.ORY_CI_RATE_LIMIT_HEADER, + process.env.ORY_CI_RATE_LIMIT_HEADER_VALUE, ) }