Query matcher issue

1. Caddy version (caddy version):


2. How I run Caddy:

a. System environment:

Caddy runs on Docker, in Kubernetes.

b. Command:

APP_BASIC_AUTH_PASSWORD_HASHED=$(caddy hash-password --plaintext $APP_BASIC_AUTH_PASSWORD) caddy run --config /etc/caddy/Caddyfile.json

c. Service/unit/compose file:

FROM caddy:${CADDY_VERSION}-builder-alpine AS builder

RUN xcaddy build \
    --with github.com/caddy-dns/route53@${ROUTE53_VERSION} \
    --with github.com/gamalan/caddy-tlsredis@${TLSREDIS_VERSION}

FROM caddy:${CADDY_VERSION}-alpine
COPY --from=builder /usr/bin/caddy /usr/bin/caddy

RUN apk --no-cache add curl


COPY static/root /

CMD ["scaddy"]

scaddy is the command outlined above.

d. My complete Caddyfile or JSON config:

The JSON config was too large to place here so I copied it to a Gist - Query matcher example · GitHub

3. The problem I’m having:

An initial config is loaded first. Then the above config is pulled from a remote source. That is when the error message is observed.

4. Error messages and/or full log output:

running dynamically-loaded config failed

loading http app module: provision http: server secure: setting up route handlers: route 5: loading handler modules: position 0: loading module ‘subroute’: provision http.handlers.subroute: setting up subroutes: route 5: loading matcher modules: module name ‘query’: decoding module config: http.matchers.query: json: cannot unmarshal array into Go value of type caddyhttp.MatchQuery

5. What I already tried:

I’ve tried a bunch of different formats, but I can’t get anything to work.

Another problem I’m having is I don’t know if I should include the initial ? that is found in all query strings in the http.matchers.query value. The documentation doesn’t provide any clues.

6. Links to relevant resources:

query takes a JSON object, where keys are the query keys, and the values are an array of string values to match for that key. So it should be like:

"query": {
	"objectid": ["268FE25C-C7DB-E12A-96278890362C135C"]

If you want to match any value, you may use * for the value.

Both keys and values may be placeholders.


Hey @francislavoie,

Great thanks! I’ll give it a shot.

Did I miss some documentation on this?


JSON documentation is autogenerated from godocs (i.e. comments in the code), so no, not really. I agree it’s not clear as-is.

The query matcher module page does essentially show the structure I described, i.e. { "": [""] } which is generated from the Go type declaration for the module, but yeah, doesn’t explain much.

What I wrote above was essentially from reading the code, and from what I know from how the query matcher works in the Caddyfile. The Caddyfile syntax is set up to sorta mimic how it reads in the URL, but it gets parsed down to the JSON structure I described.

1 Like

Hey @francislavoie,

That solved my problem. Thank you very much for the speedy support.



This topic was automatically closed after 30 days. New replies are no longer allowed.