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 |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1592 |
Signature | hs.httpserver.hsminweb.statusCodes |
---|---|
Type | Constant |
Description | HTTP Response Status Codes |
Notes |
|
Source | extensions/httpserver/httpserver_hsminweb.lua line 1644 |
Signature | hs.httpserver.hsminweb._accessLog |
---|---|
Type | Variable |
Description | Accessed as |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1552 |
Signature | hs.httpserver.hsminweb._errorHandlers |
---|---|
Type | Variable |
Description | Accessed as |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1556 |
Signature | hs.httpserver.hsminweb._serverAdmin |
---|---|
Type | Variable |
Description | Accessed as |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1546 |
Signature | hs.httpserver.hsminweb._supportMethods |
---|---|
Type | Variable |
Description | Accessed as |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1574 |
Signature | hs.httpserver.hsminweb.log |
---|---|
Type | Variable |
Description | The |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1639 |
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/httpserver_hsminweb.lua line 1597 |
Signature | hs.httpserver.hsminweb.urlParts(url) -> table |
---|---|
Type | Function |
Description | Parse the specified URL into its constituent parts. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/httpserver_hsminweb.lua line 1608 |
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/httpserver_hsminweb.lua line 1505 |
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/httpserver_hsminweb.lua line 1367 |
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/httpserver_hsminweb.lua line 1183 |
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/httpserver_hsminweb.lua line 1156 |
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/httpserver_hsminweb.lua line 1277 |
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/httpserver_hsminweb.lua line 1297 |
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/httpserver_hsminweb.lua line 1254 |
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/httpserver_hsminweb.lua line 1206 |
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/httpserver_hsminweb.lua line 1104 |
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/httpserver_hsminweb.lua line 1417 |
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/httpserver_hsminweb.lua line 1320 |
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/httpserver_hsminweb.lua line 1075 |
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/httpserver_hsminweb.lua line 1020 |
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/httpserver_hsminweb.lua line 1045 |
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/httpserver_hsminweb.lua line 992 |
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/httpserver_hsminweb.lua line 1230 |
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/httpserver_hsminweb.lua line 1343 |
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/httpserver_hsminweb.lua line 1128 |
Signature | hs.httpserver.hsminweb:start() -> hsminwebTable |
---|---|
Type | Method |
Description | Start serving pages for the hsminweb web server. |
Parameters |
|
Returns |
|
Source | extensions/httpserver/httpserver_hsminweb.lua line 1448 |
Signature | hs.httpserver.hsminweb:stop() -> hsminwebTable |
---|---|
Type | Method |
Description | Stop serving pages for the hsminweb web server. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/httpserver_hsminweb.lua line 1479 |