@@ -3,7 +3,7 @@ import { Elysia } from 'elysia';
3
3
export type IPHeaders = 'x-real-ip' | 'x-client-ip' | 'cf-connecting-ip' | 'fastly-client-ip' | 'x-cluster-client-ip' | 'x-forwarded' | 'forwarded-for' | 'forwarded' | 'x-forwarded' | 'appengine-user-ip' | 'true-client-ip' | 'cf-pseudo-ipv4' | ( string & { } )
4
4
export const headersToCheck : IPHeaders [ ] = [
5
5
'x-real-ip' , // Nginx proxy/FastCGI
6
- 'x-client-ip' , // Apache https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html#page-header
6
+ 'x-client-ip' , // Apache https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html#page-header
7
7
'cf-connecting-ip' , // Cloudflare
8
8
'fastly-client-ip' , // Fastly
9
9
'x-cluster-client-ip' , // GCP
@@ -13,7 +13,7 @@ export const headersToCheck: IPHeaders[] = [
13
13
'x-forwarded' , // RFC 7239
14
14
'appengine-user-ip' , // GCP
15
15
'true-client-ip' , // Akamai and Cloudflare
16
- 'cf-pseudo-ipv4' , // Cloudflare
16
+ 'cf-pseudo-ipv4' , // Cloudflare
17
17
]
18
18
19
19
export const getIP = ( headers : Headers , checkHeaders : IPHeaders [ ] = headersToCheck ) => {
@@ -35,10 +35,17 @@ export const ip = (config: {
35
35
* @default ['x-real-ip', 'x-client-ip', 'cf-connecting-ip', 'fastly-client-ip', 'x-cluster-client-ip', 'x-forwarded', 'forwarded-for', 'forwarded', 'x-forwarded', 'appengine-user-ip', 'true-client-ip', 'cf-pseudo-ipv4']
36
36
*/
37
37
checkHeaders ?: IPHeaders [ ]
38
- } = { } ) => ( app : Elysia ) => {
38
+ /**
39
+ * Only check headers regardless of the runtime environment
40
+ * @default false
41
+ */
42
+ headersOnly ?: boolean
43
+ } = {
44
+ headersOnly : false
45
+ } ) => ( app : Elysia ) => {
39
46
return app . derive ( { as : 'global' } , ( { request } ) => {
40
47
// @ts -ignore
41
- if ( globalThis . Bun ) {
48
+ if ( ! config . headersOnly && globalThis . Bun ) {
42
49
if ( ! app . server ) throw new Error ( `Elysia server is not initialized. Make sure to call Elyisa.listen()` )
43
50
return {
44
51
ip : app . server . requestIP ( request )
0 commit comments