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:
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.
Signature | hs.httpserver.hsminweb.dateFormatString |
---|---|
Type | Constant |
Description | A format string, usable with `os.date`, which will display a date in the format expected for HTTP communications as described in RFC 822, updated by RFC 1123. |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb.statusCodes |
---|---|
Type | Constant |
Description | HTTP Response Status Codes |
Notes | |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb._accessLog |
---|---|
Type | Variable |
Description | Accessed as `self._accessLog`. If query logging is enabled for the web server, an Apache style common log entry will be appended to this string for each request. See [hs.httpserver.hsminweb:queryLogging](#queryLogging). |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb._errorHandlers |
---|---|
Type | Variable |
Description | Accessed as `self._errorHandlers[errorCode]`. A table whose keyed entries specify the function to generate the error response page for an HTTP error. |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb._serverAdmin |
---|---|
Type | Variable |
Description | Accessed as `self._serverAdmin`. A string containing the administrator for the web server. Defaults to the currently logged in user's short form username and the computer's localized name as returned by `hs.host.localizedName()` (e.g. "user@computer"). |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb._supportMethods |
---|---|
Type | Variable |
Description | Accessed as `self._supportMethods[method]`. A table whose keyed entries specify whether or not a specified HTTP method is supported by this server. |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb.log |
---|---|
Type | Variable |
Description | The `hs.logger` instance for the `hs.httpserver.hsminweb` module. See the documentation for `hs.logger` for more information. |
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb.formattedDate([date]) -> string |
---|---|
Type | Function |
Description | Returns the current or specified time in the format expected for HTTP communications as described in RFC 822, updated by RFC 1123. |
Parameters |
|
Returns |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb.urlParts(url) -> table |
---|---|
Type | Function |
Description | Parse the specified URL into it's constituant parts. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb.new([documentRoot]) -> hsminwebTable |
---|---|
Type | Constructor |
Description | Create a new hsminweb table object representing a Hammerspoon Web Server. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:accessList([table]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the access-list table for the hsminweb web server |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:allowDirectory([flag]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the whether or not a directory index is returned when the requested URL specifies a directory and no file matching an entry in the directory indexes table is found. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:bonjour([flag]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the whether or not the web server should advertise itself via Bonjour when it is running. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:cgiEnabled([flag]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the whether or not CGI file execution is enabled. |
Parameters |
|
Returns |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:cgiExtensions([table]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the file extensions which identify files which should be executed as CGI scripts to provide the results to an HTTP request. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:directoryIndex([table]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the file names to look for when the requested URL specifies a directory. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:dnsLookup([flag]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the whether or not DNS lookups are performed. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:documentRoot([path]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the document root for the web server. |
Parameters |
|
Returns |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:interface([interface]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the network interface that the hsminweb web server will listen on |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:luaTemplateExtension([string]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the extension of files which contain Lua code which should be executed within Hammerspoon to provide the results to an HTTP request. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:maxBodySize([size]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the maximum body size for an HTTP request |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:name([name]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the name the web server uses in Bonjour advertisement when the web server is running. |
Parameters |
|
Returns |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:password([password]) -> hsminwebTable | boolean |
---|---|
Type | Method |
Description | Set a password for the hsminweb web server, or return a boolean indicating whether or not a password is currently set for the web server. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:port([port]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the name the port the web server listens on |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:queryLogging([flag]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the whether or not requests to this web server are logged. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:scriptTimeout([integer]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the timeout for a CGI script |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:ssl([flag]) -> hsminwebTable | current-value |
---|---|
Type | Method |
Description | Get or set the whether or not the web server utilizes SSL for HTTP request and response communications. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:start() -> hsminwebTable |
---|---|
Type | Method |
Description | Start serving pages for the hsminweb web server. |
Parameters |
|
Returns |
|
Source | extensions/httpserver/hsminweb.lua |
Signature | hs.httpserver.hsminweb:stop() -> hsminwebTable |
---|---|
Type | Method |
Description | Stop serving pages for the hsminweb web server. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/hsminweb.lua |