-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
how to get connectinfo(remoteAddress) #379
Comments
biluohc
changed the title
how to get connectinfo(remote)
how to get connectinfo(remoteAddress)
Jul 14, 2022
Hi @biluohc If your script run on Cloudflare Workers, you can get it by app.get('/', (c) => {
console.log(c.req.header('x-real-ip'))
return c.text('foo')
}) On Deno and Bun, we don't have any way to get the client remote address. |
Thanks. The second parameter of the Handler is ConnInfo in the the standard library of Deno, consider supporting it? |
Solved. export function sa(da: Deno.Addr) {
if (["tcp", "udp"].includes(da.transport)) {
const a = (da as Deno.NetAddr);
return `${a.hostname}:${a.port}`;
} else {
const a = (da as Deno.UnixAddr);
return a.path;
}
}
serve(async (request: Request, ci: ConnInfo) => {
const env = { sa: sa(ci.remoteAddr) };
return app.fetch(request, env)
}) |
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: