File tree 4 files changed +45
-22
lines changed
4 files changed +45
-22
lines changed Original file line number Diff line number Diff line change
1
+ import { Elysia } from "elysia"
2
+ import { swagger } from "@elysiajs/swagger"
3
+
4
+ import { ip } from "../src"
5
+ import { Server } from "bun"
6
+
7
+ let server : Server | null
8
+
9
+ const app = new Elysia ( )
10
+ . use ( swagger ( ) )
11
+ . use ( ip ( ) )
12
+ . get ( "/" , ( { ip } ) => ( { hello : ip } ) )
13
+ . listen ( 3000 , ( ) => {
14
+ console . log ( "🦊 Swagger is active at: http://localhost:3000/swagger" )
15
+ } )
16
+
17
+ server = app . server
Original file line number Diff line number Diff line change 27
27
" ip"
28
28
],
29
29
"scripts" : {
30
+ "dev" : " bun run --hot example/basic.ts" ,
30
31
"build" : " rm -rf dist && tsc --project tsconfig.esm.json" ,
31
32
"lint" : " eslint . --ext .ts"
32
33
},
36
37
"@typescript-eslint/eslint-plugin" : " ^7.8.0" ,
37
38
"@typescript-eslint/parser" : " ^7.8.0" ,
38
39
"elysia" : " ^1.0.16" ,
39
- "eslint" : " ^9.1.1 " ,
40
+ "eslint" : " ^9.2.0 " ,
40
41
"typescript" : " ^5.4.5"
41
42
},
42
43
"peerDependencies" : {
43
44
"elysia" : " >= 1.0.9"
45
+ },
46
+ "dependencies" : {
47
+ "@elysiajs/swagger" : " ^1.0.5"
44
48
}
45
49
}
Original file line number Diff line number Diff line change @@ -9,26 +9,28 @@ export const plugin = (userOptions?: Partial<Options>) => (app: Elysia) => {
9
9
...userOptions ,
10
10
}
11
11
12
- return new Elysia ( {
13
- name : "elysia-ip" ,
14
- } ) . derive ( { as : "global" } , ( { request } ) : { ip : string } => {
15
- if ( ! options . headersOnly && globalThis . Bun ) {
16
- const socketAddress = options . injectServer ( app ) ?. requestIP ( request )
17
- if ( socketAddress ) return { ip : socketAddress . address }
18
- else {
19
- console . log (
20
- `Elysia server is not initialized. Make sure to call Elyisa.listen()` ,
21
- )
22
- console . log ( `use injectServer to inject Server instance` )
12
+ return app . use (
13
+ new Elysia ( {
14
+ name : "elysia-ip" ,
15
+ } ) . derive ( { as : "global" } , ( { request } ) : { ip : string } => {
16
+ if ( ! options . headersOnly && globalThis . Bun ) {
17
+ const socketAddress = options . injectServer ( app ) ?. requestIP ( request )
18
+ if ( socketAddress ) return { ip : socketAddress . address }
19
+ else {
20
+ console . log (
21
+ `Elysia server is not initialized. Make sure to call Elyisa.listen()` ,
22
+ )
23
+ console . log ( `use injectServer to inject Server instance` )
24
+ }
23
25
}
24
- }
25
- return {
26
- ip :
27
- getIP ( request . headers , options . checkHeaders ) ||
28
- ( function ( ) {
29
- console . log ( "Failed to get ip from header!" )
30
- return ""
31
- } ) ( ) ,
32
- }
33
- } )
26
+ return {
27
+ ip :
28
+ getIP ( request . headers , options . checkHeaders ) ||
29
+ ( function ( ) {
30
+ console . log ( "Failed to get ip from header!" )
31
+ return ""
32
+ } ) ( ) ,
33
+ }
34
+ } ) ,
35
+ )
34
36
}
You can’t perform that action at this time.
0 commit comments