Skip to content

Commit 83f143c

Browse files
Merge remote-tracking branch 'upstream/main' into server-null-fix
2 parents 2d78fce + 8fcd08a commit 83f143c

File tree

10 files changed

+35
-43
lines changed

10 files changed

+35
-43
lines changed

example/issue.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Elysia } from "elysia"
2-
// import { defaultOptions, ip } from "elysia-ip"
32
import { defaultOptions, ip } from "../src/index"
43

54
import type { Server } from "bun"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elysia-ip",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"type": "module",
55
"author": {
66
"name": "Gaurish Sethia",

src/constants/headerlist.ts src/constants.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPHeaders } from "../types/header"
1+
import { Options, IPHeaders } from "./types"
22

33
export const headersToCheck: IPHeaders[] = [
44
"x-real-ip", // Nginx proxy/FastCGI
@@ -14,3 +14,9 @@ export const headersToCheck: IPHeaders[] = [
1414
"true-client-ip", // Akamai and Cloudflare
1515
"cf-pseudo-ipv4", // Cloudflare
1616
]
17+
18+
export const defaultOptions: Options = {
19+
headersOnly: false,
20+
checkHeaders: headersToCheck,
21+
injectServer: (app) => app.server,
22+
}

src/constants/defaultOptions.ts

-8
This file was deleted.

src/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
export { getIP } from "./services/getip"
22
export { plugin as ip } from "./services/plugin"
33

4-
export { defaultOptions } from "./constants/defaultOptions"
5-
export { headersToCheck } from "./constants/headerlist"
6-
7-
export type { IPHeaders } from "./types/header"
8-
export type { Options } from "./types/options"
9-
export type { injectServer } from "./types/injectserver"
4+
export { defaultOptions, headersToCheck } from "./constants"
5+
export type { IPHeaders, Options, InjectServer} from "./types"

src/services/getip.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { headersToCheck } from "../constants/headerlist"
2-
import { IPHeaders } from "../types/header"
1+
import { headersToCheck } from "../constants"
2+
import { IPHeaders } from "../types"
33

44
export const getIP = (
55
headers: Headers,

src/services/plugin.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Elysia } from "elysia"
2-
import { getIP } from "../services/getip"
3-
import { defaultOptions } from "../constants/defaultOptions"
4-
import type { Options } from "../types/options"
2+
import { getIP } from "./getip"
3+
import { defaultOptions } from "../constants"
4+
import type { Options } from "../types"
55

66
export const plugin = (userOptions?: Partial<Options>) => (app: Elysia) => {
77
const options: Options = {

src/types/options.ts src/types.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
import type { IPHeaders } from "./header"
2-
import type { injectServer } from "./injectserver"
1+
import type { Server } from "bun"
2+
import type Elysia from "elysia"
3+
4+
export type IPHeaders =
5+
| "x-real-ip"
6+
| "x-client-ip"
7+
| "cf-connecting-ip"
8+
| "fastly-client-ip"
9+
| "x-cluster-client-ip"
10+
| "x-forwarded"
11+
| "forwarded-for"
12+
| "forwarded"
13+
| "x-forwarded"
14+
| "appengine-user-ip"
15+
| "true-client-ip"
16+
| "cf-pseudo-ipv4"
17+
| (string & {})
18+
19+
export type InjectServer = (app: Elysia) => Server | null
320

421
export interface Options {
522
/**
@@ -15,5 +32,5 @@ export interface Options {
1532
/**
1633
*
1734
*/
18-
injectServer: injectServer
35+
injectServer: InjectServer
1936
}

src/types/header.ts

-14
This file was deleted.

src/types/injectserver.ts

-4
This file was deleted.

0 commit comments

Comments
 (0)