Allow express 'trust proxy' to be set #3274
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to Rate limiting when behind a proxy or load balancer discussion.
I was able to test this change and verify manually while running Verdaccio locally.
I did attempt to add some unit tests for this to test/unit/modules/api/api.spec.ts as well. I ran into issues in that regard as it doesn't appear the
app.set('trust proxy', config.server.trustProxy);
has any effect when supertest is being leveraged. I'm not sure why this is the case. I've provided an example unit test below. No matter what I tried, the following issues were encountered:X-Forwarded-For
header, thereq.ip
field would still resolve to127.0.0.1
from the express handler. I verified this when a break point was placed at src/api/endpoint/api/ping.ts:7. This is not the expected behavior or the behavior exhibited when actually running Verdaccio.res.req.ip
property being checked in the test would always resolve toundefined
. It seems that value is unavailable in the unit test as it gets cleared out after the response is sent. Even if it was available, based on bullet point #1, it would not be the expected value.Attempted unit tests that wouldn't work:
test/unit/modules/api/api.spec.ts