elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.23k stars 198 forks source link

Client IP is always 'null' #599

Open Joschi84 opened 3 months ago

Joschi84 commented 3 months ago

What version of Elysia.JS is running?

Elysia: command not found

What platform is your computer?

Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Hello Community,

I'm trying to get the client IP Address, but i only always get 'null'. What I am doing wrong? Hopefully someone can help. Elysia is working well (even if 'Elysia --revision' gives Elysia: command not found). Bun is on the newest Version (1.1.3). And Elysia should be also very up-to-date. Here is the code:

import { Elysia } from "elysia";

const app = new Elysia()
  .use(app => app.derive(({ request }) => ({ ip: app.server?.requestIP(request) })))
  .post("/test", async ({ body, ip }) => {
      console.log(body, ip) 
  })
  .listen(2000)

What is the expected behavior?

Getting client ip address.

What do you see instead?

null

Additional information

No response

kidqueb commented 3 months ago

Your snippet works for me when logging ip, but it is currently logging id.

Joschi84 commented 3 months ago

My fault. I edited it. But this was just a typing error here in the browser. For me, the problem remains unclear. Any further ideas?