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

requestIP return null when using sign cookie #655

Closed
armada45-pixel opened this issue May 23, 2024 · 3 comments
Closed

requestIP return null when using sign cookie #655

armada45-pixel opened this issue May 23, 2024 · 3 comments
Labels
blocking Blocked by other issues bug Something isn't working

Comments

@armada45-pixel
Copy link

armada45-pixel commented May 23, 2024

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!🚧" : ""
      }`,
    )
  })
@armada45-pixel armada45-pixel added the bug Something isn't working label May 23, 2024
@SaltyAom
Copy link
Member

Blocking on oven-sh/bun#6613

@SaltyAom SaltyAom added the blocking Blocked by other issues label Aug 30, 2024
@kravetsone
Copy link
Contributor

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
Copy link
Author

Wait for testing.

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

No branches or pull requests

3 participants