nice-router
A nice, simpler router for handling those pesky HTTP(S) requests.
Example
var Router = ;var router = ;router;router;router;
Basic HTTPS example
To use this example you will need to generate self-signed certificates server.key
and
server.crt
. If you are unsure about how to do that, see this Stack
Overflow.
var fs = ;var Router = ;var router = ;router
Methods
#addRoute(path, method, handler)
: Adds a route to the router which will respond tomethod
requests topath
by doinghandler
. The signature of handlers ishandler(request, response, headers, query, body)
. Therequest
andresponse
objects are the same as those from the nodehttp
/https
modules.headers
andquery
are basic key/value objects.body
is a Buffer, so callbody.toString("utf-8")
if you just want a string.#listen(port) -> Promise
: Start the server on the specified port, which must be open.#close -> Promise
: Stop the server.#useHTTPS(options[, callback])
: Switches the server to using HTTPS, restarting if the server was already running.options
is the same as the options parameter in node'shttps.createServer
. Accepts an optionalcallback
which will be called if the server is restarted.#addStatic(path, contentType)
: Adds a handler which responds toGET
requests atpath
with the contents of the file atpath
.