# Interface TemplatedApp

TemplatedApp is either an SSL or non-SSL app. See App for more info, read user manual.

interface TemplatedApp {
addChildAppDescriptor(descriptor: AppDescriptor): void;
addServerName(hostname: string, options: AppOptions): TemplatedApp;
any(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
close(): TemplatedApp;
connect(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
del(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
domain(domain: string): TemplatedApp;
filter(
cb: (res: HttpResponse, count: Number) => void | Promise<void>,
): TemplatedApp;
get(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
getDescriptor(): AppDescriptor;
head(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
listen(
host: RecognizedString,
port: number,
cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
): TemplatedApp;
listen(
host: RecognizedString,
port: number,
options: ListenOptions,
cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
): TemplatedApp;
listen(
port: number,
cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
): TemplatedApp;
listen(
port: number,
options: ListenOptions,
cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
): TemplatedApp;
listen_unix(
cb: (listenSocket: us_listen_socket) => void | Promise<void>,
path: RecognizedString,
): TemplatedApp;
missingServerName(cb: (hostname: string) => void): TemplatedApp;
numSubscribers(topic: RecognizedString): number;
options(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
patch(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
post(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
publish(
topic: RecognizedString,
message: RecognizedString,
isBinary?: boolean,
compress?: boolean,
): boolean;
put(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
removeChildAppDescriptor(descriptor: AppDescriptor): void;
removeServerName(hostname: string): TemplatedApp;
trace(
pattern: RecognizedString,
handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
): TemplatedApp;
ws<UserData>(
pattern: RecognizedString,
behavior: WebSocketBehavior<UserData>,
): TemplatedApp;
}

- Defined in index.d.ts:333

##### Index

### Methods

addChildAppDescriptor
addServerName
any
close
connect
del
domain
filter
get
getDescriptor
head
listen
listen_unix
missingServerName
numSubscribers
options
patch
post
publish
put
removeChildAppDescriptor
removeServerName
trace
ws

## Methods

### addChildAppDescriptor

- addChildAppDescriptor(descriptor: AppDescriptor): void

  Add a child app descriptor for worker thread distribution.

  #### Parameters

  - descriptor: AppDescriptor

  #### Returns void

  - Defined in index.d.ts:385

### addServerName

- addServerName(hostname: string, options: AppOptions): TemplatedApp

  Adds a server name.

  #### Parameters

  - hostname: string
  - options: AppOptions

  #### Returns TemplatedApp

  - Defined in index.d.ts:371

### any

- any(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP handler matching specified URL pattern on any HTTP method.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:363

### close

- close(): TemplatedApp

  Closes all sockets including listen sockets. This will forcefully terminate all connections.

  #### Returns TemplatedApp

  - Defined in index.d.ts:381

### connect

- connect(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP CONNECT handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:359

### del

- del(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP DELETE handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:351

### domain

- domain(domain: string): TemplatedApp

  Browse to SNI domain. Used together with .get, .post and similar to attach routes under SNI domains.

  #### Parameters

  - domain: string

  #### Returns TemplatedApp

  - Defined in index.d.ts:373

### filter

- filter(
  cb: (res: HttpResponse, count: Number) => void | Promise<void>,
  ): TemplatedApp

  Attaches a "filter" function to track socket connections / disconnections

  #### Parameters

  - cb: (res: HttpResponse, count: Number) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:379

### get

- get(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP GET handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:345

### getDescriptor

- getDescriptor(): AppDescriptor

  Returns the app descriptor for worker thread distribution.

  #### Returns AppDescriptor

  - Defined in index.d.ts:383

### head

- head(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP HEAD handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:357

### listen

- listen(
  host: RecognizedString,
  port: number,
  cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
  ): TemplatedApp

  Listens to hostname & port. Callback hands either false or a listen socket.

  #### Parameters

  - host: RecognizedString
  - port: number
  - cb: (listenSocket: false | us_listen_socket) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:335
- listen(
  host: RecognizedString,
  port: number,
  options: ListenOptions,
  cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
  ): TemplatedApp

  Listens to hostname & port and sets Listen Options. Callback hands either false or a listen socket.

  #### Parameters

  - host: RecognizedString
  - port: number
  - options: ListenOptions
  - cb: (listenSocket: false | us_listen_socket) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:337
- listen(
  port: number,
  cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
  ): TemplatedApp

  Listens to port. Callback hands either false or a listen socket.

  #### Parameters

  - port: number
  - cb: (listenSocket: false | us_listen_socket) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:339
- listen(
  port: number,
  options: ListenOptions,
  cb: (listenSocket: false | us_listen_socket) => void | Promise<void>,
  ): TemplatedApp

  Listens to port and sets Listen Options. Callback hands either false or a listen socket.

  #### Parameters

  - port: number
  - options: ListenOptions
  - cb: (listenSocket: false | us_listen_socket) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:341

### listen_unix

- listen_unix(
  cb: (listenSocket: us_listen_socket) => void | Promise<void>,
  path: RecognizedString,
  ): TemplatedApp

  Listens to unix socket. Callback hands either false or a listen socket.

  #### Parameters

  - cb: (listenSocket: us_listen_socket) => void | Promise<void>
  - path: RecognizedString

  #### Returns TemplatedApp

  - Defined in index.d.ts:343

### missingServerName

- missingServerName(cb: (hostname: string) => void): TemplatedApp

  Registers a synchronous callback on missing server names. See /examples/ServerName.js.

  #### Parameters

  - cb: (hostname: string) => void

  #### Returns TemplatedApp

  - Defined in index.d.ts:377

### numSubscribers

- numSubscribers(topic: RecognizedString): number

  Returns number of subscribers for this topic.

  #### Parameters

  - topic: RecognizedString

  #### Returns number

  - Defined in index.d.ts:369

### options

- options(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP OPTIONS handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:349

### patch

- patch(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP PATCH handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:353

### post

- post(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP POST handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:347

### publish

- publish(
  topic: RecognizedString,
  message: RecognizedString,
  isBinary?: boolean,
  compress?: boolean,
  ): boolean

  Publishes a message under topic, for all WebSockets under this app. See WebSocket.publish.

  #### Parameters

  - topic: RecognizedString
  - message: RecognizedString
  - `Optional` isBinary: boolean
  - `Optional` compress: boolean

  #### Returns boolean

  - Defined in index.d.ts:367

### put

- put(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP PUT handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:355

### removeChildAppDescriptor

- removeChildAppDescriptor(descriptor: AppDescriptor): void

  Remove a child app descriptor.

  #### Parameters

  - descriptor: AppDescriptor

  #### Returns void

  - Defined in index.d.ts:387

### removeServerName

- removeServerName(hostname: string): TemplatedApp

  Removes a server name.

  #### Parameters

  - hostname: string

  #### Returns TemplatedApp

  - Defined in index.d.ts:375

### trace

- trace(
  pattern: RecognizedString,
  handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>,
  ): TemplatedApp

  Registers an HTTP TRACE handler matching specified URL pattern.

  #### Parameters

  - pattern: RecognizedString
  - handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>

  #### Returns TemplatedApp

  - Defined in index.d.ts:361

### ws

- ws<UserData>(
  pattern: RecognizedString,
  behavior: WebSocketBehavior<UserData>,
  ): TemplatedApp

  Registers a handler matching specified URL pattern where WebSocket upgrade requests are caught.

  #### Type Parameters

  - UserData

  #### Parameters

  - pattern: RecognizedString
  - behavior: WebSocketBehavior<UserData>

  #### Returns TemplatedApp

  - Defined in index.d.ts:365