Skip to content

Commit 4fcbf6c

Browse files
committed
fix: typing issues
1 parent b44e29e commit 4fcbf6c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/define_config.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type UserDefinedServerConfig = Partial<
2121
* Define configuration for the HTTP server
2222
*/
2323
export function defineConfig(config: UserDefinedServerConfig): ServerConfig {
24+
const { trustProxy, ...rest } = config
25+
2426
const normalizedConfig = {
2527
allowMethodSpoofing: false,
2628
trustProxy: proxyAddr.compile('loopback'),
@@ -51,18 +53,26 @@ export function defineConfig(config: UserDefinedServerConfig): ServerConfig {
5153
skipNulls: false,
5254
},
5355
},
54-
...config,
56+
...rest,
5557
}
5658

59+
/**
60+
* Normalizing maxAge property on cookies to be a number in
61+
* seconds
62+
*/
5763
if (normalizedConfig.cookie.maxAge) {
5864
normalizedConfig.cookie.maxAge = string.seconds.parse(normalizedConfig.cookie.maxAge)
5965
}
6066

61-
if (typeof normalizedConfig.trustProxy === 'boolean') {
62-
const tpValue = normalizedConfig.trustProxy
67+
/**
68+
* Normalizing trust proxy setting to allow boolean and
69+
* string values
70+
*/
71+
if (typeof trustProxy === 'boolean') {
72+
const tpValue = trustProxy
6373
normalizedConfig.trustProxy = (_, __) => tpValue
64-
} else if (typeof normalizedConfig.trustProxy === 'string') {
65-
const tpValue = normalizedConfig.trustProxy
74+
} else if (typeof trustProxy === 'string') {
75+
const tpValue = trustProxy
6676
normalizedConfig.trustProxy = proxyAddr.compile(tpValue)
6777
}
6878

0 commit comments

Comments
 (0)