#
hs.httpserver.hsminweb
Minimalist Web Server for Hammerspoon
This module aims to be a minimal, but (mostly) standards-compliant web server for use within Hammerspoon. Expanding upon the Hammerspoon module, hs.httpserver
, this module adds support for serving static pages stored at a specified document root as well as serving dynamic content from Lua Template Files interpreted within the Hammerspoon environment and external executables which support the CGI/1.1 framework.
This module aims to provide a fully functional, and somewhat extendable, web server foundation, but will never replace a true dedicated web server application. Some limitations include:
- It is single threaded within the Hammerspoon environment and can only serve one resource at a time
- As with all Hammerspoon modules, while dynamic content is being generated, Hammerspoon cannot respond to other callback functions -- a complex or time consuming script may block other Hammerspoon activity in a noticeable manner.
- All document requests and responses are handled in memory only -- because of this, maximum resource size is limited to what you are willing to allow Hammerspoon to consume and memory limitations of your computer.
While some of these limitations may be mitigated to an extent in the future with additional modules and additions to hs.httpserver
, Hammerspoon's web serving capabilities will never replace a dedicated web server when volume or speed is required.
An example web site is provided in the hsdocs
folder of the hs.doc
module. This web site can serve documentation for Hammerspoon dynamically generated from the json file included with the Hammerspoon application for internal documentation. It serves as a basic example of what is possible with this module.
You can start this web server by typing the following into your Hammerspoon console:
require("hs.doc.hsdocs").start()
and then visiting http://localhost:12345/
with your web browser.
#
Submodules
#
API Overview
Constants - Useful values which cannot be changed
dateFormatString statusCodes
Variables - Configurable values
_accessLog _errorHandlers _serverAdmin _supportMethods log
Functions - API calls offered directly by the extension
formattedDate urlParts
Constructors - API calls which return an object, typically one that offers API methods
new
Methods - API calls which can only be made on an object returned by a constructor
accessList allowDirectory bonjour cgiEnabled cgiExtensions directoryIndex dnsLookup documentRoot interface luaTemplateExtension maxBodySize name password port queryLogging scriptTimeout ssl start stop