Clojure library for interacting with Caddy via the HTTP Admin API
Tested with Caddy v2.2.1
[cawdy "0.3.1"]
cawdy {:mvn/version "0.3.1"}
Creates a new server that listens on :2015 and serves two domains. One that
gives a static response (:static
) for all requests and one that serves files
from a directory (:files
)
(require '[cawdy.core :as cawdy])
(def conn (cawdy/connect "http://localhost:2019")
(cawdy/create-server conn {:listen [":2015"]})
(cawdy/add-route conn :my-id "cawdy-response.example" :static {:body "hello"}))
(cawdy/add-route conn :my-id "cawdy-files.example" :files {:root "/etc"}))
(require '[cawdy.core :as cawdy])
(def conn (cawdy/connect "http://localhost:2019")
(cawdy/config conn)
=> {:apps
{:http
{:servers
{:my-id
{:listen ["localhost:2016"],
:routes
[{:handle
[{:handler "file_server", :root "/tmp/cawdytest2"}]}]}}}}})
(cawdy/create-server conn {:listen [":2019"]})
(cawdy/add-route conn :my-id "localhost" :static {:body "This gets returned"}))
$ curl --silent localhost:2019
This gets returned
Options for :static handler can be:
:body
- What to send in the response body
(cawdy/create-server conn {:listen [":2020"]})
(cawdy/add-route conn :my-id "localhost" :static {:root "/etc"}))
$ curl --silent localhost:2020/hosts
# Static table lookup for hostnames.
...
Options for :files handler are:
:root
- What directory should act as the root directory
Run tests with make test
that will automatically download a compatible
Caddy version to run the tests with. It'll also start caddy with no config,
and turn it off after the tests.
Don't run the tests with a caddy instance whos config is important as the tests will remove the existing config before each test.
Copyright © 2020 Victor Bjelkholm under MIT license, see LICENSE