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

request ip unavailable in web handler #968

Open
huseeiin opened this issue Feb 4, 2025 · 1 comment
Open

request ip unavailable in web handler #968

huseeiin opened this issue Feb 4, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@huseeiin
Copy link

huseeiin commented Feb 4, 2025

Environment

Bun 1.2.0
H3 1.13.0

Reproduction

import { createApp, getRequestIP, toWebHandler } from "h3";

export default {
    fetch: toWebHandler(createApp().use((ev) => typeof getRequestIP(ev))),
};

Describe the bug

when using node adapter (in bun or deno), this bug doesn't happen and the ip exists:

import { createApp, getRequestIP, toNodeListener } from "h3";
import { createServer } from "http";

createServer(
    toNodeListener(createApp().use((ev) => typeof getRequestIP(ev)))
).listen(3000);

Additional context

same bug in deno and wrangler dev (cloudflare)

Logs

@huseeiin huseeiin added the bug Something isn't working label Feb 4, 2025
@ManUtopiK
Copy link

Cloudflare pages use the header x-real-ip.
So, to be sure to get the ip, i did this :

const ip = getRequestIP(event) || getRequestHeader(event, 'x-real-ip')

But getRequestIP should return the IP for any platforms...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants