From 87d7fc9e0a53c8de59207b12cf544cb332c5d941 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 21 May 2024 18:39:15 +0530 Subject: [PATCH] refactor: relay trustProxy value as it is in normalizedConfig --- src/define_config.ts | 2 ++ tests/define_config.spec.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/define_config.ts b/src/define_config.ts index df90add..6c292af 100644 --- a/src/define_config.ts +++ b/src/define_config.ts @@ -74,6 +74,8 @@ export function defineConfig(config: UserDefinedServerConfig): ServerConfig { } else if (typeof trustProxy === 'string') { const tpValue = trustProxy normalizedConfig.trustProxy = proxyAddr.compile(tpValue) + } else if (trustProxy) { + normalizedConfig.trustProxy = trustProxy } return normalizedConfig diff --git a/tests/define_config.spec.ts b/tests/define_config.spec.ts index ae8bca5..b68a8e5 100644 --- a/tests/define_config.spec.ts +++ b/tests/define_config.spec.ts @@ -9,6 +9,7 @@ import { test } from '@japa/runner' import { defineConfig } from '../index.js' +import proxyAddr from 'proxy-addr' test.group('Define config', () => { test('define server config', ({ assert }) => { @@ -58,4 +59,10 @@ test.group('Define config', () => { assert.typeOf(config.trustProxy, 'function') }) + + test('compile trustProxy config when a function', ({ assert }) => { + const fn = proxyAddr.compile(['192.168.1.2']) + const config = defineConfig({ trustProxy: fn }) + assert.strictEqual(config.trustProxy, fn) + }) })