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

[Feature Request] Deepkit RPC: Getting connection info e.g., client IP & http request header #594

Open
kkimdev opened this issue Jul 8, 2024 · 1 comment

Comments

@kkimdev
Copy link

kkimdev commented Jul 8, 2024

IP information is useful for various purposes like rate-limiting, logging, etc, ... I believe that popular RPC libraries usually have a way to access that info. (e.g., we're using gRPC and it's included in the message metadata)

@kkimdev
Copy link
Author

kkimdev commented Jul 9, 2024

update: I was able to get the IP with the below approach. Though my server is behind Cloudflare & Kubernetes so need to check http request headers("CF-Connecting-IP" or "x-forwarded-for") to get the public client IP :/, oh well...

@rpc.controller("/test")
export class TestService {
  constructor(private connection: RpcKernelBaseConnection) {}

  @rpc.action()
  getClientIp() {
    return this.connection.clientAddress() || "It's undefined";
  }
}

@kkimdev kkimdev changed the title [Feature Request] Deepkit RPC: Getting connection info e.g., client IP [Feature Request] Deepkit RPC: Getting connection info e.g., client IP & http request header Jul 9, 2024
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

No branches or pull requests

1 participant