diff --git a/caddy/Caddyfile b/caddy/Caddyfile new file mode 100644 index 0000000..e996716 --- /dev/null +++ b/caddy/Caddyfile @@ -0,0 +1,20 @@ +{ + # to use handle_path for prefixes, pmtiles_proxy must have a defined + # position in the ordering of handlers. + order pmtiles_proxy before reverse_proxy +} + +localhost:2019 { + handle_path /tiles/* { + pmtiles_proxy { + + # replace with your bucket URL or http path + bucket https://example.com + + cache_size 256 + + # used to embed a tiles URL in TileJSON. + public_hostname https://localhost:2019/tiles + } + } +} diff --git a/caddy/pmtiles_proxy.go b/caddy/pmtiles_proxy.go index 0313ed0..42d8074 100644 --- a/caddy/pmtiles_proxy.go +++ b/caddy/pmtiles_proxy.go @@ -22,10 +22,11 @@ func init() { } type Middleware struct { - Bucket string `json:"bucket"` - CacheSize int `json:"cache_size"` - logger *zap.Logger - server *pmtiles.Server + Bucket string `json:"bucket"` + CacheSize int `json:"cache_size"` + PublicHostname string `json:"public_hostname"` + logger *zap.Logger + server *pmtiles.Server } func (Middleware) CaddyModule() caddy.ModuleInfo { @@ -39,7 +40,7 @@ func (m *Middleware) Provision(ctx caddy.Context) error { m.logger = ctx.Logger() logger := log.New(io.Discard, "", log.Ldate) prefix := "." // serve only the root of the bucket for now, at the root route of Caddyfile - server, err := pmtiles.NewServer(m.Bucket, prefix, logger, 64, "", "https://example.com") + server, err := pmtiles.NewServer(m.Bucket, prefix, logger, m.CacheSize, "", m.PublicHostname) if err != nil { return err } @@ -89,6 +90,10 @@ func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.ArgErr() } m.CacheSize = num + case "public_hostname": + if !d.Args(&m.PublicHostname) { + return d.ArgErr() + } } } }