Module ringo/httpserver

A wrapper for the Jetty HTTP server.

Class Context

Instance Methods

Class Server

Instance Methods


Context.prototype.addServlet (servletPath, servlet, initParams)

Map a request path within this context to the given servlet.

Parameters

string servletPath the servlet path
Servlet servlet a java object implementing the javax.servlet.Servlet interface.
Object initParams optional object containing servlet init parameters

Context.prototype.serveApplication (app, engine)

Map this context to a JSGI application.

Parameters

function|object app a JSGI application, either as a function or an object with properties config and app defining the application.
{ config: 'config', app: 'app' }
RhinoEngine engine optional RhinoEngine instance for multi-engine setups

Context.prototype.serveStatic (dir)

Map this context to a directory containing static resources.

Parameters

string dir the directory from which to serve static resources

Server (options)

Create a Jetty HTTP server with the given options. The options may either define properties to be used with the default jetty.xml, or define a custom configuration file.

Parameters

Object options A javascript object with any of the following properties, with the default value in parentheses:
  • jettyConfig ('config/jetty.xml')
  • port (8080)
  • host (undefined)
For convenience, the constructor supports the definition of a JSGI application and static resource mapping in the config object using the following properties:
  • virtualHost (undefined)
  • mountpoint ('/')
  • staticDir ('static')
  • staticMountpoint ('/static')
  • config ('config')
  • app ('app')

Server.prototype.destroy ()

Destroy the HTTP server, freeing its resources.


Server.prototype.getContext (path, virtualHosts, options)

Get a servlet application context for the given path and virtual hosts, creating it if it doesn't exist.

Parameters

string path the context root path such as "/" or "/app"
string|array virtualHosts optional single or multiple virtual host names. A virtual host may start with a "*." wildcard.
Object options may have the following properties: sessions: true to enable sessions for this context, false otherwise security: true to enable security for this context, false otherwise

Returns

a Context object

Server.prototype.getDefaultContext ()

Get the server's default context. The default context is the context that is created when the server is created.

Returns

the default context

Server.prototype.getJetty ()

Get the Jetty server instance

Returns

the Jetty Server instance

Server.prototype.isRunning ()

Checks whether this server is currently running.

Returns

true if the server is running, false otherwise.

Server.prototype.start ()

Start the HTTP server.


Server.prototype.stop ()

Stop the HTTP server.