Remote IP available through context-object #132
+277
−56
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.
PURPOSE
getRemoteIp()
forquery
/mutation
/action
, returning the remote IP on the connectionCAVEAT
Depending on how Convex Cloud is load-balanced, this might or might not work. If the service is setup using Layer 7 load balancers, this will not work as it relies on
X-Forwarded-For
being set, which this PR doesn't honor (but can be made to, conceptually).If it is balanced using Layer 4 with NLB, this will probably work with Convex Cloud as it usually passes on the source IP-address directly.
It will very likely work for standalone backend.
Also: I am not sure it needs to be implemented as a function call, but it was not obvious how to have this available when V8 is initialized. Implementing it as a property directly on
ctx
would incur some unwanted overhead as JavaScript needs to call back into Rust, which we want to avoid in the common case.USAGE
TEST RUN
For me, this is currently the same as the
main
-branch, so I don't think errors are introduced that tests would catch.CODE QUALITY
This PR needs to be looked after by a seasoned Convex developer as it is my first attempt at making something in Convex core. If it is rejected, feel free to use it as inspiration for a proper implementation.
IMPROVEMENTS (potential)
getRemoteIp
andgetRemotePort
, perhaps, currently the port is returned withgetRemoteIp
on the format127.0.0.1:57345
.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.