Class GlobalContext

Constructors

  • Parameters

    • options: {
          bind: string;
          compression: {
              http: {
                  enabled: boolean;
                  maxSize: number;
                  minSize: number;
                  preferOrder: CompressionAlgorithm[];
              };
              ws: {
                  enabled: boolean;
                  maxSize: number;
              };
          };
          logging: {
              debug: boolean;
              error: boolean;
              warn: boolean;
          };
          methods: {
              head: boolean;
              trace: boolean;
          };
          performance: {
              eTag: boolean;
              lastModified: boolean;
          };
          port: number;
          proxy: {
              compress: boolean;
              credentials: {
                  authenticate: boolean;
                  password: string;
                  username: string;
              };
              enabled: boolean;
              force: boolean;
              header: Lowercase<string>;
              ips: {
                  list: (Subnet<4 | 6> | IPAddress<4 | 6>)[];
                  mode: "whitelist" | "blacklist";
                  validate: boolean;
              };
          };
          version: boolean;
      }
      • bind: string

        THe IP Address to bind the server to

        Default

        "0.0.0.0"
        

        Since

        0.0.4

      • compression: {
            http: {
                enabled: boolean;
                maxSize: number;
                minSize: number;
                preferOrder: CompressionAlgorithm[];
            };
            ws: {
                enabled: boolean;
                maxSize: number;
            };
        }

        Various Compression-Related Settings

        Since

        9.0.0

        • http: {
              enabled: boolean;
              maxSize: number;
              minSize: number;
              preferOrder: CompressionAlgorithm[];
          }

          HTTP Compression Settings

          Since

          9.0.0

          • enabled: boolean

            Whether HTTP Compression is enabled

            Default

            true
            

            Since

            9.0.0

          • maxSize: number

            The Maximum Size of an Item allowed to be compressed

            Default

            size(10).mb()
            

            Since

            9.0.0

          • minSize: number

            The Minimum Size of an Item allowed to be compressed

            Default

            size(1).kb()
            
          • preferOrder: CompressionAlgorithm[]

            The Order in which to prefer Compression Algorithms, non included wont be used

            Default

            ["brotli", "gzip", "deflate"]
            

            Since

            9.0.0

        • ws: {
              enabled: boolean;
              maxSize: number;
          }

          WebSocket Compression Settings

          Since

          9.0.0

          • enabled: boolean

            Whether WebSocket Compression is enabled

            Default

            true
            

            Since

            9.0.0

          • maxSize: number

            The Maximum Size of an Item allowed to be compressed

            Default

            size(1).mb()
            

            Since

            9.0.0

      • logging: {
            debug: boolean;
            error: boolean;
            warn: boolean;
        }

        Various Logging-Related Settings

        Since

        7.4.0

        • debug: boolean

          Whether to enable DEBUG Logs

          Default

          false
          

          Since

          7.4.0

        • error: boolean

          Whether to enable ERROR Logs

          Default

          true
          

          Since

          7.4.0

        • warn: boolean

          Whether to enable WARN Logs

          Default

          true
          

          Since

          7.4.0

      • methods: {
            head: boolean;
            trace: boolean;
        }

        The HTTP Methods that should automatically be handled for you

        Since

        9.5.0

        • head: boolean

          Whether to automatically handle HEAD Requests

          Default

          true
          

          Since

          9.5.0

        • trace: boolean

          Whether to automatically handle TRACE Requests

          Default

          false
          

          Since

          9.5.0

      • performance: {
            eTag: boolean;
            lastModified: boolean;
        }

        Various Performance-Related Settings

        Since

        6.3.0

        • eTag: boolean

          Whether to include ETag Headers on every request with a direct Body

          Default

          true
          

          Since

          6.3.0

        • lastModified: boolean

          Whether to include Last-Modified Headers on every request that serves a file

          Default

          true
          

          Since

          6.3.0

      • port: number

        The Port to use for the Server, can be random using 0

        Default

        0
        

        Since

        0.0.1

      • proxy: {
            compress: boolean;
            credentials: {
                authenticate: boolean;
                password: string;
                username: string;
            };
            enabled: boolean;
            force: boolean;
            header: Lowercase<string>;
            ips: {
                list: (Subnet<4 | 6> | IPAddress<4 | 6>)[];
                mode: "whitelist" | "blacklist";
                validate: boolean;
            };
        }

        HTTP Proxy Options

        Since

        8.0.0

        • compress: boolean

          Whether to compress the requests

          Default

          false
          

          Since

          9.0.0

        • credentials: {
              authenticate: boolean;
              password: string;
              username: string;
          }

          The Credentials that the proxy will use

          Since

          8.0.0

          • authenticate: boolean

            Whether to authenticate proxy requests

            Default

            false
            

            Since

            8.0.0

          • password: string

            The Password required to authenticate

            Default

            "proxy"
            

            Since

            8.0.0

          • username: string

            The Username required to authenticate

            Default

            "proxy"
            

            Since

            8.0.0

        • enabled: boolean

          Whether to check for proxies and use alternate IPs

          Default

          false
          

          Since

          8.0.0

        • force: boolean

          Whether to force all requests through the proxy

          Default

          false
          

          Since

          8.0.0

        • header: Lowercase<string>

          The Header to use for getting the actual IP address, it must only include the IP address

          Default

          "x-forwarded-for"
          

          Since

          8.0.0

        • ips: {
              list: (Subnet<4 | 6> | IPAddress<4 | 6>)[];
              mode: "whitelist" | "blacklist";
              validate: boolean;
          }

          The IPs the server will validate against

          Since

          9.0.0

          • list: (Subnet<4 | 6> | IPAddress<4 | 6>)[]

            The List of Authorized (or Unauthorized) Proxy IPs

            Default

            [...ReverseProxyIps.LOCAL, ...ReverseProxyIps.CLOUDFLARE]
            

            Since

            9.0.0

          • mode: "whitelist" | "blacklist"

            The Mode in which to validate the list

            Default

            "whitelist"
            

            Since

            9.0.0

          • validate: boolean

            Whether to validate proxy ips

            Default

            false
            

            Since

            9.0.0

      • version: boolean

        Whether to add the rjweb-server header that contains the version

        Default

        true
        

        Since

        9.0.0

    • implementation: Implementation
    • classContexts: ClassContexts

    Returns GlobalContext

Properties

cache: {
    arrayBufferTexts: {
        proxy_auth_invalid: ArrayBufferLike;
        proxy_auth_required: ArrayBufferLike;
        rate_limit_exceeded: ArrayBufferLike;
        route_not_found: ArrayBufferLike;
    };
    compressionMethods: ValueCollection<string, CompressionAlgorithm, CompressionAlgorithm>;
    emptyArrayBuffer: ArrayBuffer;
    proxyCredentials: string;
    staticFiles: ValueCollection<string, [path: string, route: default<"static">], [path: string, route: default<"static">]>;
} = ...

Caches for various methods

Type declaration

  • arrayBufferTexts: {
        proxy_auth_invalid: ArrayBufferLike;
        proxy_auth_required: ArrayBufferLike;
        rate_limit_exceeded: ArrayBufferLike;
        route_not_found: ArrayBufferLike;
    }

    Cached ArrayBuffer Texts

    Since

    9.0.0

    • proxy_auth_invalid: ArrayBufferLike
    • proxy_auth_required: ArrayBufferLike
    • rate_limit_exceeded: ArrayBufferLike
    • route_not_found: ArrayBufferLike
  • compressionMethods: ValueCollection<string, CompressionAlgorithm, CompressionAlgorithm>

    The Cache for the Compression Methods Header parsing

    Since

    9.0.0

  • emptyArrayBuffer: ArrayBuffer

    An Empty ArrayBuffer

    Since

    9.7.0

  • proxyCredentials: string

    The Cached base64 encoded proxy credentials

    Since

    9.0.0

  • staticFiles: ValueCollection<string, [path: string, route: default<"static">], [path: string, route: default<"static">]>

    The Cache for static files

    Since

    9.0.0

Since

9.0.0

channels: Channel<Content>[] = []

Channels that were used with the server

Since

9.0.0

classContexts: ClassContexts

Class Contexts used to create the ctr object

Since

9.0.0

contentTypes: ValueCollection<string, string, string> = ...

Content Type Mappings

Since

9.0.0

errorHandlers: ErrorCallbacks<any, any> = {}

The Error handlers

Since

9.0.0

finishHandlers: FinishCallbacks<any, any> = {}

The Finish handlers

Since

9.0.0

httpHandler: null | ((ctr, end) => any) = null

The HTTP callback handler

Type declaration

Since

9.0.0

implementation: Implementation
internalChannelStringIdentifiers: Map<string, Channel<any>> = ...

Internal Channel String Identifiers

Since

9.8.0

internalRequestIdentifiers: Set<number> = ...

Internal Request Identifiers

Since

9.3.0

logger: default

The Logger for Internal Events

Since

9.0.0

notFoundHandler: null | ((ctr) => any) = null

The Not Found handler

Type declaration

Since

9.0.0

options: {
    bind: string;
    compression: {
        http: {
            enabled: boolean;
            maxSize: number;
            minSize: number;
            preferOrder: CompressionAlgorithm[];
        };
        ws: {
            enabled: boolean;
            maxSize: number;
        };
    };
    logging: {
        debug: boolean;
        error: boolean;
        warn: boolean;
    };
    methods: {
        head: boolean;
        trace: boolean;
    };
    performance: {
        eTag: boolean;
        lastModified: boolean;
    };
    port: number;
    proxy: {
        compress: boolean;
        credentials: {
            authenticate: boolean;
            password: string;
            username: string;
        };
        enabled: boolean;
        force: boolean;
        header: Lowercase<string>;
        ips: {
            list: (Subnet<4 | 6> | IPAddress<4 | 6>)[];
            mode: "whitelist" | "blacklist";
            validate: boolean;
        };
    };
    version: boolean;
}

The Options for the Server

Type declaration

  • bind: string

    THe IP Address to bind the server to

    Default

    "0.0.0.0"
    

    Since

    0.0.4

  • compression: {
        http: {
            enabled: boolean;
            maxSize: number;
            minSize: number;
            preferOrder: CompressionAlgorithm[];
        };
        ws: {
            enabled: boolean;
            maxSize: number;
        };
    }

    Various Compression-Related Settings

    Since

    9.0.0

    • http: {
          enabled: boolean;
          maxSize: number;
          minSize: number;
          preferOrder: CompressionAlgorithm[];
      }

      HTTP Compression Settings

      Since

      9.0.0

      • enabled: boolean

        Whether HTTP Compression is enabled

        Default

        true
        

        Since

        9.0.0

      • maxSize: number

        The Maximum Size of an Item allowed to be compressed

        Default

        size(10).mb()
        

        Since

        9.0.0

      • minSize: number

        The Minimum Size of an Item allowed to be compressed

        Default

        size(1).kb()
        
      • preferOrder: CompressionAlgorithm[]

        The Order in which to prefer Compression Algorithms, non included wont be used

        Default

        ["brotli", "gzip", "deflate"]
        

        Since

        9.0.0

    • ws: {
          enabled: boolean;
          maxSize: number;
      }

      WebSocket Compression Settings

      Since

      9.0.0

      • enabled: boolean

        Whether WebSocket Compression is enabled

        Default

        true
        

        Since

        9.0.0

      • maxSize: number

        The Maximum Size of an Item allowed to be compressed

        Default

        size(1).mb()
        

        Since

        9.0.0

  • logging: {
        debug: boolean;
        error: boolean;
        warn: boolean;
    }

    Various Logging-Related Settings

    Since

    7.4.0

    • debug: boolean

      Whether to enable DEBUG Logs

      Default

      false
      

      Since

      7.4.0

    • error: boolean

      Whether to enable ERROR Logs

      Default

      true
      

      Since

      7.4.0

    • warn: boolean

      Whether to enable WARN Logs

      Default

      true
      

      Since

      7.4.0

  • methods: {
        head: boolean;
        trace: boolean;
    }

    The HTTP Methods that should automatically be handled for you

    Since

    9.5.0

    • head: boolean

      Whether to automatically handle HEAD Requests

      Default

      true
      

      Since

      9.5.0

    • trace: boolean

      Whether to automatically handle TRACE Requests

      Default

      false
      

      Since

      9.5.0

  • performance: {
        eTag: boolean;
        lastModified: boolean;
    }

    Various Performance-Related Settings

    Since

    6.3.0

    • eTag: boolean

      Whether to include ETag Headers on every request with a direct Body

      Default

      true
      

      Since

      6.3.0

    • lastModified: boolean

      Whether to include Last-Modified Headers on every request that serves a file

      Default

      true
      

      Since

      6.3.0

  • port: number

    The Port to use for the Server, can be random using 0

    Default

    0
    

    Since

    0.0.1

  • proxy: {
        compress: boolean;
        credentials: {
            authenticate: boolean;
            password: string;
            username: string;
        };
        enabled: boolean;
        force: boolean;
        header: Lowercase<string>;
        ips: {
            list: (Subnet<4 | 6> | IPAddress<4 | 6>)[];
            mode: "whitelist" | "blacklist";
            validate: boolean;
        };
    }

    HTTP Proxy Options

    Since

    8.0.0

    • compress: boolean

      Whether to compress the requests

      Default

      false
      

      Since

      9.0.0

    • credentials: {
          authenticate: boolean;
          password: string;
          username: string;
      }

      The Credentials that the proxy will use

      Since

      8.0.0

      • authenticate: boolean

        Whether to authenticate proxy requests

        Default

        false
        

        Since

        8.0.0

      • password: string

        The Password required to authenticate

        Default

        "proxy"
        

        Since

        8.0.0

      • username: string

        The Username required to authenticate

        Default

        "proxy"
        

        Since

        8.0.0

    • enabled: boolean

      Whether to check for proxies and use alternate IPs

      Default

      false
      

      Since

      8.0.0

    • force: boolean

      Whether to force all requests through the proxy

      Default

      false
      

      Since

      8.0.0

    • header: Lowercase<string>

      The Header to use for getting the actual IP address, it must only include the IP address

      Default

      "x-forwarded-for"
      

      Since

      8.0.0

    • ips: {
          list: (Subnet<4 | 6> | IPAddress<4 | 6>)[];
          mode: "whitelist" | "blacklist";
          validate: boolean;
      }

      The IPs the server will validate against

      Since

      9.0.0

      • list: (Subnet<4 | 6> | IPAddress<4 | 6>)[]

        The List of Authorized (or Unauthorized) Proxy IPs

        Default

        [...ReverseProxyIps.LOCAL, ...ReverseProxyIps.CLOUDFLARE]
        

        Since

        9.0.0

      • mode: "whitelist" | "blacklist"

        The Mode in which to validate the list

        Default

        "whitelist"
        

        Since

        9.0.0

      • validate: boolean

        Whether to validate proxy ips

        Default

        false
        

        Since

        9.0.0

  • version: boolean

    Whether to add the rjweb-server header that contains the version

    Default

    true
    

    Since

    9.0.0

Since

9.0.0

rateLimitHandlers: RatelimitCallbacks<any, any> = {}

The Ratelimit Handlers

Since

9.0.0

rateLimits: ValueCollection<`http+${string}-${number}` | `ws+${string}-${number}`, {
    end: number;
    hits: number;
}, {
    end: number;
    hits: number;
}> = ...

Rate Limit Store

Type declaration

  • end: number
  • hits: number

Type declaration

  • end: number
  • hits: number

Since

9.0.0

routes: {
    http: default<"http">[];
    static: default<"static">[];
    ws: default<"ws">[];
} = ...

The Routes available for searching

Type declaration

  • http: default<"http">[]
  • static: default<"static">[]
  • ws: default<"ws">[]

Since

9.0.0