Skip to content
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

Closed
wants to merge 8 commits into from
Closed

Fix/connot set trust proxy #654

wants to merge 8 commits into from

Conversation

yazaldefilimone
Copy link
Contributor

Checklist

@yazaldefilimone
Copy link
Contributor Author

yazaldefilimone commented Aug 10, 2023

#654

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina requested a review from Eomm August 11, 2023 08:06
@@ -23,13 +23,14 @@ const DEFAULT_ARGUMENTS = {

module.exports = function parseArgs (args) {
dotenv.config()
const TRUST_PROXY = process.env.TRUST_PROXY || ''
Copy link
Member

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

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'],
Copy link
Member

Choose a reason for hiding this comment

The 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 FASTIFY_ENABLE_TRUST_PROXY

Comment on lines +69 to +71
const isNumber = isNaN(Number(TRUST_PROXY)) === false
const isTrue = TRUST_PROXY.toLowerCase() === 'true'
const trustProxy = isNumber ? Number(TRUST_PROXY) : isTrue
Copy link
Member

Choose a reason for hiding this comment

The 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 parsedArgs will win if the user set a boolean.. I would hardly understand the behaviour here.

KIS approach:

  • one env per boolean
  • one env per trust proxy hosts
  • one env per trust hop

the priority is the list i wrote when user set multiple env vars

@Eomm Eomm linked an issue Aug 13, 2023 that may be closed by this pull request
2 tasks
@yazaldefilimone yazaldefilimone closed this by deleting the head repository Mar 2, 2024
@twalling
Copy link
Contributor

@Eomm it seems this PR was closed, we use fastify-cli in production and need to set trustProxy now so I'd be happy to submit a PR based on the feedback it seems you had

Am I correct in reading this that for this more flexible fastify argument the preference would be 2-3 explicit arguments (named appropriately) for the various use cases and then just go through choosing the one to use based on the priority list you mentioned?

@twalling twalling mentioned this pull request Oct 29, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot set trustProxy with fastify-cli
4 participants