Skip to content

francislavoie/caddy-hcl

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

caddy-hcl

Go

Caddy config adapter for HCL (HashiCorp Configuration Language)

A significant chunk of the code is borrowed from https://github.com/tmccombs/hcl2json, credit to them for figuring out the HCL to JSON conversion.

Install

Install with xcaddy.

xcaddy build \
    --with github.com/francislavoie/caddy-hcl

Or download from the Caddy website: https://caddyserver.com/download

Usage

Specify the --adapter flag to caddy run

caddy run --config /path/to/hcl/caddy.hcl --adapter hcl

Limitations

Note that currently, HCL block syntax is not properly supported, because of ambiguity in the HCL syntax which makes objects at the end of blocks get wrapped with an array. This meant that block syntax generates JSON that Caddy considers invalid, because for example, it expects objects as the value for each server. Ideally, if I had my way, the config would look more like this (but this doesn't work):

apps http servers srv0 {
    ...
}

Example

Here's an example of a simple proxy server.

apps = {
  http = {
    servers = {
      srv0 = {
        listen = [":443"]

        routes = [
          {
            match = [{ host = ["example.com"] }]
            handle = [{
              handler = "subroute"
              routes = [{
                handle = [{
                  handler = "reverse_proxy"
                  upstreams = [{ dial = "localhost:8000" }]
                }]
              }]
            }]

            terminal = true
          }
        ]
      }
    }
  }
}

About

Caddy config adapter for HCL (HashiCorp Config Language)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages