About Wub: Domains/Nub

The Nub module controls the dispatch function of Wub. Nub allows you to configure server's response to requests by defining a mapping from request-URLs to Domain handlers.

Dispatch is controlled by a collection of nubs, which are mappings from a URL glob to content or to a Domain handler. Nubs may be collected together in configuration files, or updated online via the Nub domain.

Note that the URLs associated with nubs may contain host components. If they do, the nub will match only requests directed to that host. This is how 'virtual domains' can be implemented. The host component (and the path component) may also contain * as wildcards.

Defining Nubs

Nubs may be defined with the [Nub domain] command in the following form:

[Nub domain urldomainargs...]

where url is the url prefix which will be handled by this nub, domain is the handler for this nub, and args are the constructor arguments for the domain. Domains are modules of code which transform a request dict into a response dict.

Nubs may be defined by invoking the [Nub domain] command directly from tcl, but Nub loads a set of nub files when it is constructed, and also supports a Web interface for definition, saving and editing of nubs.

Synthetic Nubs

The following synthetic nubs are available to pre-filter or manipulate the URL request, or to provide immediate content:

instructs the server to place an IP address which attempts to access a matching URL onto a block list, preventing it from accessing the server in future.

<url> redirect <to>

Sends the client a redirect which causes it to attempt to load the specified 'to' URL.

<url> code <script> ?<content-type>?

Returns the result of evaluating the supplied tcl script in the Nub namespace.

<url> literal <literal> ?<content-type>?

Returns specified literal content to client.

<url> rewrite <script> or <url> rewrite -regsub <subspec>

Transforms a URL (selected by regexp) into another (as calculate by the rewrite tcl script, which is evaluated in the Nub namespace). The rewrite script has access to all fields of the request, as elements of the dict variable named 'r'. If the -regsub form is used, then <url> and <subspec> function as the exp and subspec elements of tcl's [regsub] command, whose result is returned.

Nub as a Domain handler

Nub is itself a domain handler which presents a web interface through which a (suitably credentialed) user can create new nubs, edit or delete existing nubs, and apply nubs to the currently running server. The Nub domain itself may be mapped into the URL space by: [Nub domain /nub/ Nub].