Server Class

The Server class is the main class for the server. It extends the Router class. It serves the following purposes.
  • • Define and manage routes for execution, analytics and building purposes.
  • • Providing a generic interface to handle requests from HTTP, WHATWG, WebSocket, CLI, etc.
  • • Being the main context of all event and route action callbacks.
  • • Manages all the project configurations.
  • • Bootstrap plugins. Plugins can register and configure themselves by listening to the , , and events.
  • • Resolve and load pathnames and filepaths.

config

Generic arbitrary configuration map used by plugins to auto configure itself.
Copy

gateway

Sets the gateway in which HTTP requests originate from and how to handle them.
Copy

entries

Returns a map of route entries that are logged using . You can use this to compare against the and properties for analytics and building production code. Entries are mapped like the following where entry is a filepath instead of an action function.
Copy

Example

Copy

handler

A callback that handles resource requests (ie. HTTP, WHATWG, WebSocket, CLI, etc.).
Copy

imports

Returns a map of route imports that are logged using . You can use this to compare against the and properties for analytics and building production code. Imports are mapped like the following where import is a no-argument callback that returns an import ie. .
Copy

Example

Copy

listeners

Returns a read-only shallow copy of the listeners. Listeners are organized by events and events can have multiple listeners and listeners have priorities. The listeners are not pre-organized by priority. This happens during the event loop.
Copy

loader

Returns the plugin loader.
Copy

plugins

Returns a map of plugin names to their respective interface.
Copy

routes

Returns all the routes that are registered with the server. You can use this to compare against the and properties for analytics and building production code. Routes are mapped like the following.
Copy

Example

Copy

views

Returns a map of route views that are logged using . You can use this to compare against the and properties for analytics and building production code. Views are mapped like the following where entry is a filepath instead of an action function.
Copy

Example

Copy

all()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

bootstrap()

Loads the plugins and allows them to self bootstrap (config, listen to events, add routes, etc.) and configure themselves.
Copy

connect()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

create()

Creates a new Node.js HTTP server
Copy

delete()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

emit()

Calls all the callbacks of the given event passing the given arguments.

Usage

Copy

Example

Copy

get()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

handle()

Handles a raw request with either Node.js HTTP IncomingMessage, and ServerResponse or WHATWG Request, and Response.
Copy

Example

Copy

head()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

on()

Adds an action callback to the given event listener.

Usage

Copy

Example

Copy

options()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

patch()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

plugin

Returns a plugin interface
Copy

post()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

put()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

register

Registers a plugin and its interface.
Copy

request()

Creates a new request.

Usage

Copy

Example

Copy
Copy
Copy
Copy
Where as the are as follows.
Copy

resolve()

Resolves an event or route. Similar to except you can pass an object as a request, and both request and response are optional.

Usage

Copy
Copy

Example

Copy
Copy
Copy
Copy

response()

Creates a new response.

Usage

Copy

Example

Copy
Copy
Copy
Where as the are as follows.
Copy

route()

Registers a route with the server.

Usage

Copy

Example

Copy
Copy
Copy

trace()

A shortcut for .

Usage

Copy

Example

Copy
Copy
Copy

use()

Allows routes from other routers to apply here.

Usage

Copy

Example

Copy