hammerspoon2-docs
    Preparing search index...

    Namespace httpserver

    Module for creating and managing HTTP servers. Create a server with hs.httpserver.create(), configure it with chainable setters, then call start(). The server accepts both synchronous and async (Promise-returning) request handler callbacks.

    const server = hs.httpserver.create()
    .setPort(8080)
    .setCallback((method, path, headers, body) => {
    return {body: "<h1>Hello from Hammerspoon!</h1>", status: 200, headers: {"Content-Type": "text/html"}}
    })
    .start()
    console.log("Listening on port " + server.getPort())
    server.setCallback(async (method, path, headers, body) => {
    const data = await hs.http.get("https://api.example.com/data")
    return {body: data.body, status: 200, headers: {"Content-Type": "application/json"}}
    })
    const server = hs.httpserver.create()
    .setPort(8080)
    .setDocumentRoot("/Users/me/Sites")
    .start()
    openssl genrsa -out key.pem 2048
    openssl req -new -x509 -key key.pem -out cert.pem -days 365
    openssl pkcs12 -export -out identity.p12 -inkey key.pem -in cert.pem
    const server = hs.httpserver.create()
    .setPort(8443)
    .setTLSFromPKCS12("/path/to/identity.p12", "passphrase")
    .setCallback(handler)
    .start()

    Functions

    create