Skip to content

Commit

Permalink
add example caddyfile; add caddy public_hostname config option [#85] (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon authored Sep 29, 2023
1 parent 1f4c412 commit 077a6d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
20 changes: 20 additions & 0 deletions caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -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
}
}
}
15 changes: 10 additions & 5 deletions caddy/pmtiles_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down

0 comments on commit 077a6d8

Please sign in to comment.