elysiajs / elysia

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

requestIP return null when using sign cookie #655

Closed armada45-pixel closed 3 weeks ago

armada45-pixel commented 4 months ago

What version of Elysia.JS is running?

1.0.21

What platform is your computer?

Alpine Linux v3.18 on Docker 4.30.0 ( Desktop ) on WSL version: 2.1.5.0 on Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

when have cookie need to sign, socketAddress from requestIP will return will

What is the expected behavior?

requestIP return normal socketAddress object

What do you see instead?

null

Additional information

import { Elysia } from "elysia"

const app = new Elysia({
  name: "mainApp",
  serve: {
    hostname: "0.0.0.0",
    port: 8082,
  },
  cookie: {
    sign: true, // If false requestIP return object of socketAddress
    secrets: process.env.COOKIE_KEY,
  },
})
  .use((app) =>
    app.derive(({ request }) => ({
      ip: app.server?.requestIP(request)?.address,
    })),
  )
  .derive({ as: "global" }, ({ cookie: { someMilk } }) => ({
    get milkType() {
      const value = "chocolate milk"
      someMilk.set({
        value: value,
      })
      return value
    },
  }))
  .get("/", ({ ip }) => {
    return ip + "some message"
  })
  .listen({}, ({ development, hostname, port }) => {
    console.log(
      `🦊 Elysia is running at ${hostname}:${port} ${
        development ? "🚧 in development mode!🚧" : ""
      }`,
    )
  })
SaltyAom commented 1 month ago

Blocking on https://github.com/oven-sh/bun/issues/6613

kravetsone commented 3 weeks ago

Fixed by Bun@1.1.27

import { Elysia } from "elysia";

const app = new Elysia({
    name: "mainApp",
    serve: {
        port: 8082,
    },
    cookie: {
        sign: true, // If false requestIP return object of socketAddress
        secrets: process.env.COOKIE_KEY || "ok",
    },
})
    .use((app) =>
        app.derive(({ request }) => ({
            ip: app.server?.requestIP(request)?.address,
        }))
    )
    .derive({ as: "global" }, ({ cookie: { someMilk } }) => ({
        get milkType() {
            const value = "chocolate milk";
            someMilk.set({
                value: value,
            });
            return value;
        },
    }))
    .get("/", ({ ip }) => {
        return ip + "some message";
    })
    .listen({}, ({ development, hostname, port }) => {
        console.log(
            `🦊 Elysia is running at ${hostname}:${port} ${
                development ? "🚧 in development mode!🚧" : ""
            }`
        );
    });

image

armada45-pixel commented 3 weeks ago

Wait for testing.