Class WsCloseContext<Context>

Type Parameters

  • Context extends Record<any, any> = {}

Hierarchy

Constructors

Properties

@: Context = ...

Context Variables that are available anywhere in the requests lifespan

Since

1.2.1

client: {
    internal: boolean;
    ip: IPAddress<4 | 6>;
    origin: string;
    port: number;
    proxied: boolean;
    referrer: string;
    userAgent: string;
}

Client Infos

Type declaration

  • Readonly internal: boolean

    Whether the Client IP Address is from an internal fetch

    Since

    9.3.0

  • Readonly ip: IPAddress<4 | 6>

    The IP Address that the Client is using

    When a valid Proxy Request is made (and proxy is enabled) this will be the proper IP

    Since

    3.0.0

  • Readonly origin: string

    The Origin of the Clients Request

    Since

    9.5.0

    Example

    localhost:8000
    
  • Readonly port: number

    The Port that the Client is using

    Since

    3.0.0

  • Readonly proxied: boolean

    Whether the Client IP Address is proxied

    Since

    9.3.0

  • Readonly referrer: string

    The Referrer of the Clients Request

    Since

    9.5.0

    Example

    https://localhost:8000/me
    
  • Readonly userAgent: string

    The User Agent of the Client

    Since

    3.0.0

context: RequestContext<any>

The Request Context Object used by the server

Since

9.0.0

The Global Context Object used by the server

Since

9.0.0

headers: ValueCollection<string, string, Content>

A Collection of all Headers

Example

if (ctr.headers.has('authorization')) console.log('Authorization Header is present')

console.log(ctr.headers.get('authorization')) // Will print undefined if not present
console.log(ctr.headers.get('authorization', 'hello')) // Will print 'hello' if not present

Since

2.0.0

params: BaseCollection<string, string>

A Collection of all Path Parameters

Example

console.log(ctr.params.get('server')) // Will print undefined if not present

Since

2.0.0

server: Server<{}, [], {}>

The Server Object that initialized this Request

Type declaration

    Type declaration

      Since

      9.8.0

      type: "close" = 'close'

      The Type of this Websocket Event

      Since

      5.7.0

      url: default

      The Requested URL

      Since

      0.0.2

      Accessors

      • get cookies(): ValueCollection<string, string, Cookie>
      • A Collection of all Client Cookies

        Returns ValueCollection<string, string, Cookie>

        Example

        import { Cookie } from "rjweb-server"

        if (ctr.cookies.has('theme')) console.log('Theme Cookie is present')

        console.log(ctr.cookies.get('theme')) // Will print undefined if not present
        console.log(ctr.cookies.get('theme', 'light')) // Will print 'light' if not present

        ctr.cookies.set('session', new Cookie(Math.random(), {
        path: '/'
        }))

        Since

        2.0.0

      • get fragments(): BaseCollection<string, string>
      • A Collection of all URL Fragments

        Returns BaseCollection<string, string>

        Example

        if (ctr.fragments.has('user')) console.log('User Fragment is present')

        console.log(ctr.fragments.get('user')) // Will print undefined if not present
        console.log(ctr.fragments.get('user', 'default')) // Will print 'default' if not present

        Since

        7.0.0

      • get queries(): BaseCollection<string, string>
      • A Collection of all URL Queries

        Returns BaseCollection<string, string>

        Example

        if (ctr.queries.has('user')) console.log('User Query is present')

        console.log(ctr.queries.get('user')) // Will print undefined if not present
        console.log(ctr.queries.get('user', 'default')) // Will print 'default' if not present

        Since

        2.0.0

      Methods

      • Grab a Channel from either a string identifier or a Channel object

        Type Parameters

        Parameters

        Returns Channel<C>

        Example

        const channel = ctr.$channel('channel')

        await channel.send('text', 'Ok')

        // or

        const ref = new Channel<string>()
        const channel = ctr.$channel(ref)

        await channel.send('text', 'Ok')

        Since

        9.8.0