-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/connot set trust proxy #654
Changes from all commits
2a6092c
591a701
ea3f814
aae3516
fdf941e
3ea7318
68c0b29
b516b4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,14 @@ const DEFAULT_ARGUMENTS = { | |
|
||
module.exports = function parseArgs (args) { | ||
dotenv.config() | ||
const TRUST_PROXY = process.env.TRUST_PROXY || '' | ||
const commandLineArguments = argv(args, { | ||
configuration: { | ||
'populate--': true | ||
}, | ||
number: ['port', 'inspect-port', 'body-limit', 'plugin-timeout', 'close-grace-delay'], | ||
string: ['log-level', 'address', 'socket', 'prefix', 'ignore-watch', 'logging-module', 'debug-host', 'lang', 'require', 'config', 'method'], | ||
boolean: ['pretty-logs', 'options', 'watch', 'verbose-watch', 'debug', 'standardlint', 'common-prefix', 'include-hooks'], | ||
boolean: ['pretty-logs', 'options', 'trustProxy', 'watch', 'verbose-watch', 'debug', 'standardlint', 'common-prefix', 'include-hooks'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it has multiple shapes. fwis, string and boolean are the most used so I would support it or I would rename it to |
||
envPrefix: 'FASTIFY_', | ||
alias: { | ||
port: ['p'], | ||
|
@@ -65,7 +66,9 @@ module.exports = function parseArgs (args) { | |
|
||
// Merge objects from lower to higher priority | ||
const parsedArgs = { ...DEFAULT_ARGUMENTS, ...configFileOptions, ...commandLineArguments } | ||
|
||
const isNumber = isNaN(Number(TRUST_PROXY)) === false | ||
const isTrue = TRUST_PROXY.toLowerCase() === 'true' | ||
const trustProxy = isNumber ? Number(TRUST_PROXY) : isTrue | ||
Comment on lines
+69
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is very hard to read and it does too much logic IMHO regardless this code, the KIS approach:
the priority is the list i wrote when user set multiple env vars |
||
return { | ||
_: parsedArgs._, | ||
'--': additionalArgs, | ||
|
@@ -91,6 +94,7 @@ module.exports = function parseArgs (args) { | |
lang: parsedArgs.lang, | ||
method: parsedArgs.method, | ||
commonPrefix: parsedArgs.commonPrefix, | ||
includeHooks: parsedArgs.includeHooks | ||
includeHooks: parsedArgs.includeHooks, | ||
trustProxy: parsedArgs.trustProxy || Boolean(trustProxy) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the FASTIFY_ prefix everywhere, I would keep it