Giter Club home page Giter Club logo

elysia-ip's People

Contributors

armada45-pixel avatar gaurishhs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

elysia-ip's Issues

Cannot find module 'elysia-ip' or its corresponding type declarations.

{
  "name": "study-app",
  "version": "1.0.50",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "bun run --watch src/index.ts",
    "start": "NODE_ENV=production bun run src/index.ts"
  },
  "dependencies": {
    "@elysiajs/bearer": "^1.0.2",
    "@elysiajs/cors": "^1.0.2",
    "@elysiajs/jwt": "^1.0.2",
    "@elysiajs/static": "^1.0.2",
    "@elysiajs/swagger": "^0.8.5",
    "@types/pluralize": "^0.0.33",
    "elysia": "^1.0.10",
    "mongoose": "^8.2.1",
    "pluralize": "^8.0.0",
    "tencentcloud-sdk-nodejs-sms": "^4.0.789",
    "uuid": "^9.0.1"
  },
  "devDependencies": {
    "@types/uuid": "^9.0.8",
    "bun-types": "latest"
  },
  "module": "src/index.js"
}

I don't know what is causing the issue.

Screenshot 2024-03-31 at 06 33 09

Duplicate run when use multiple time & Add injectServer & Remove throw error it make app crash

Duplicate when use multiple time.
Fix by using new Elysia() and name it using Elysia({ name: "elysia-ip" })

Planing add option injectServer like
https://github.com/rayriffy/elysia-rate-limit/blob/main/example/muliInstanceInjected.ts
for fix issue like rayriffy/elysia-rate-limit#29

Remove throw error it make app crash

if (!app.server) throw new Error(`Elysia server is not initialized. Make sure to call Elyisa.listen()`)

Fixed in Fork
https://github.com/armada45-pixel/elysia-ip/blob/main/src/index.ts

Incorrect IP Header Priority

Description:
I'm experiencing an issue with the elysia-ip when specifying headers for IP retrieval. Despite setting cf-connecting-ip as the header to check, the middleware is still returning the IP from the x-forwarded-for header.

Node.js Version: v20.11.0
Elysia Version: v1.0.20
elysia-ip Version: v1.0.5
bun Version: v1.0.26

import { Elysia } from "elysia";
import { ip } from "elysia-ip";

const app = new Elysia()
  .use(ip({ headersOnly: true, checkHeaders: ["cf-connecting-ip"] })).get(
    "/test",
    ({ ip, request }) => {
      console.log("ip", ip);
      console.log("headers", JSON.stringify(request.headers, null, 2));
      return "777";
    },
  ).listen(3000);

console.log(
  `๐ŸฆŠ Elysia is running at ${app.server?.hostname}:${app.server?.port}`,
);

Run the following curl command to test

curl http://localhost:3000/test \
  -H 'cf-connecting-ip: 192.168.1.1' \
  -H 'x-forwarded-for: 192.168.2.2'

Observe that the console output shows the IP from x-forwarded-for instead of cf-connecting-ip.
Console Output:

ip 192.168.2.2
headers {
  "cf-connecting-ip": "192.168.1.1",
  "x-forwarded-for": "192.168.2.2"
}

returning ipv4 address as ipv6

Hi. First of all, thank you so much for this repo; it saved me a headache I was not interested in dealing with!

I'm only just getting started building out the app I'm working on, but I'm seeing this when I run the dev server and ping it from another device on my local network:

{
  address: "::ffff:192.168.1.154",
  family: "IPv6",
  port: 56144,
}

I know the client IPv4 address is 192.168.1.154; I'm not sure why it's showing up here as IPv6 though.

Better get ip from header & Readme

  • Find better way for get ip from header. (Better getIP function )
  • Default value make condition never true ( never use ).
  • but if you send false in checkHeaders param it will make condition true but will error type error

Default value

checkHeaders: IPHeaders[] = headersToCheck,

Never true condition
if (!checkHeaders && headers.get("x-forwarded-for")) {

  • Readme & Example

Does not work with Stable Elysia@v1

IP returns null. There are breaking changes with Elysia@v1. See #513.

Versions

  • elysia-ip: 0.0.7
  • elysia: 1.0.9

Reproduction

const app = new Elysia()
  .use(ip())
  .get('/', ({ ip }) => {
    console.log("ip", ip); // logs "ip null"
    return "Hello"
  })

vscode show errors when using `ip` in the Context block

Property 'ip' does not exist on type '{ body: { token: string; user: string; }; query: Record<string, string | undefined>; params: never; headers: Record<string, string | undefined>; cookie: Record<string, Cookie<any>>; set: { ...; }; path: string; request: Request; store: {}; }'.
.post("/api/UniUser/getUsers", ({ body, ip, path }) => {
    if (main.debug) logger(`audit> ${ip.address} requested ${path}`, 4);
    UniUser.getUsers(body.user, body.token)
  }, {
    body: t.Object({
      user: t.String(),
      token: t.String()
    })
  })

red underline at ip in ({ body, ip, path })

Error: Property 'ip' does not exist on type on 0.0.7

Hi! I'm running into an issue while following the basic implementation guide from the docs:

import { Elysia } from "elysia";
import { ip } from "elysia-ip";

new Elysia().use(ip()).get("/", ({ ip }) => ip).listen(3000);

On version ^0.0.7, TypeScript throws a Property 'ip' does not exist on type error for the { ip } reference.

This error disappears when I downgrade to version ^0.0.6, where ip is correctly typed as
string | SocketAddress | null | undefined

My environment is using the latest Bun version (v1.0.27), with all other dependencies up to date, including TypeScript (^5.3.3) and Elysia (^0.8.17 or latest).

I have attached screenshots to illustrate the issue (0.0.7 left, and 0.0.6 right), but please let me know if there are any issues accessing them or if further details are required.

SCR-20240219-ucfy SCR-20240219-uckv

use(ip()) causes typescript to not recognize the param types

After installing the plugin and using it like use(ip()),
the typescript engine is complaining that in route handling .get("/id/:id", ({ params: { id } }) => id), id has type any.
The same goes for other params as well: .onError(({ code, error }) => { return new Response(error.toString()); });, code and error have type any

My Elysia version is 0.8.8 and I am using version elysia-ip 0.0.5

Was there a breaking update?

Just added this package and attempted to use it as shown in the README.

I get this error from typescript:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '(app: Elysia<"", false, { decorator: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, { schema: {}; macro: {}; }, {}, { derive: {}; resolve: {}; schema: {}; }, { derive: {}; resolve: {}; schema: {}; }>) => Elysia<...>' is not assignable to parameter of type 'Promise<{ default: AnyElysia; }>'.ts(2769)
index.d.ts(777, 5): The last overload is declared here.
(alias) ip(userOptions?: Partial<Options> | undefined): (app: Elysia<"", false, {
    decorator: {};
    store: {};
    derive: {};
    resolve: {};
}, {
    type: {};
    error: {};
}, {
    schema: {};
    macro: {};
}, {}, {
    ...;
}, {
    ...;
}>) => Elysia<...>

Usage:

import { ip } from "elysia-ip"; const app = new Elysia().use(ip()).get("/", () => ({ message: "Hello Elysia" }));

package json:

"elysia": "latest",

Usage with POST request

It seems like the IP isn't included on the request object for a POST request.

{
  request: Request (0 KB) {
    method: "POST",
    url: "http://localhost:3000/get-quote",
    headers: Headers {
      "host": "localhost:3000",
      "connection": "keep-alive",
      "content-length": "138",
      "content-type": "multipart/form-data; boundary=----WebKitFormBoundarycWgoyItEDfYxlrDK",
      "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
      "accept": "*/*",
      "origin": "http://localhost:3000",
      "sec-fetch-mode": "cors",
      "sec-fetch-dest": "empty",
      "referer": "http://localhost:3000/",
      "accept-encoding": "gzip, deflate, br",
      "accept-language": "en-US,en-GB;q=0.9,en;q=0.8,fr-CA;q=0.7,fr;q=0.6",
      "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
      "x-alpine-request": "true",
      "sec-ch-ua-mobile": "?0",
      "x-alpine-target": "quote",
      "sec-ch-ua-platform": "\"macOS\"",
      "sec-fetch-site": "same-origin",
    }
  },
  store: {},
  qi: -1,
  path: "/get-quote",
  set: {
    headers: {},
    status: 200,
  },
  headers: {
    host: "localhost:3000",
    connection: "keep-alive",
    "content-length": "138",
    "content-type": "multipart/form-data; boundary=----WebKitFormBoundarycWgoyItEDfYxlrDK",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    accept: "*/*",
    origin: "http://localhost:3000",
    "sec-fetch-mode": "cors",
    "sec-fetch-dest": "empty",
    referer: "http://localhost:3000/",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "en-US,en-GB;q=0.9,en;q=0.8,fr-CA;q=0.7,fr;q=0.6",
    "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
    "x-alpine-request": "true",
    "sec-ch-ua-mobile": "?0",
    "x-alpine-target": "quote",
    "sec-ch-ua-platform": "\"macOS\"",
    "sec-fetch-site": "same-origin",
  },
  query: {},
  body: {
    testing: "",
  },
  ip: null,
  html: [Function: html],
  stream: [Function: stream],
}

Is this something that's possible to do?

Error when using multiple Elysia instances

image

elysia-ip version: 1.0.0

So you get this error whenever you write something sane like this (e.g. to separate route definitions).

const app = new Elysia()
  .use(cors())
  .use(login)
  .listen(envs.PORT);
 
const login = new Elysia()
    .use(ip())
    .post('/login', async ({ body, ip }) => {
        console.log(ip);
        ...
    });

export default login;

Unable to import

image

Tried to using example code in README. Unable to import. Any hints as to why?

Some dependency versions:

  • elysia: 1.0.9
  • elysia-ip: 1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.