Skip to content

Commit

Permalink
refactor: relay trustProxy value as it is in normalizedConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed May 21, 2024
1 parent 912fd1e commit 87d7fc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/define_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/define_config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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)
})
})

0 comments on commit 87d7fc9

Please sign in to comment.