Giter Site home page Giter Site logo

cawdy's Introduction

cawdy

Clojars Project CircleCI

Clojure library for interacting with Caddy via the HTTP Admin API

Tested with Caddy v2.2.1

Installation

Leiningen

[cawdy "0.3.1"]

deps.edn

cawdy {:mvn/version "0.3.1"}

Usage

Quickstart

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"}))

Connect to running Caddy server

(require '[cawdy.core :as cawdy])
(def conn (cawdy/connect "http://localhost:2019")

Get Current Configuration

(cawdy/config conn)
=> {:apps
    {:http
     {:servers
      {:my-id
       {:listen ["localhost:2016"],
        :routes
        [{:handle
          [{:handler "file_server", :root "/tmp/cawdytest2"}]}]}}}}})

Add Static Response Handler

(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

Add File Server Handler

(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

Tests

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.

License

Copyright © 2020 Victor Bjelkholm under MIT license, see LICENSE

cawdy's People

Contributors

victorb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.