1. The problem I’m having:
Hi, I tried to implement a Caddy module which encodes incoming request URLs using Base64 encoding and redirects clients to a specified target URL with the encoded URL appended.
My source code can be found here:
I configured it in my Caddyfile like described in 4d.
Since my console print in init()
can be found in the output, it seems to be registered, but unfortunately the rest is not working.
Thanks in advance!
2. Error messages and/or full log output:
Registering Base64Redirect module
{"level":"info","ts":1732030412.894132,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
Error: adapting config using caddyfile: parsing caddyfile tokens for 'route': unrecognized directive: base64_redirect - are you sure your Caddyfile structure (nesting and braces) is correct?, at /etc/caddy/Caddyfile:10
3. Caddy version:
Caddy v2.8.4
4. How I installed and ran Caddy:
I build Caddy with
GOOS=linux GOARCH=amd64 xcaddy build --with github.com/jomo02/base64-redirect
and run it via Docker (Compose)
a. System environment:
Ubuntu 20.04.6 LTS
Docker 27.1.0
Docker Compose version v2.29.0
b. Command:
docker compose up -d
c. Compose file:
caddy:
image: caddy:2
ports:
- 80:80
- 443:443
- 443:443/udp
volumes:
- ./caddy:/usr/bin/caddy
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./caddy-config:/config
- ./caddy-data:/data
d. My complete Caddy config:
{
debug
}
http://domain1.com {
route {
base64_redirect {
target https://domain2.com/viewer/
}
}
}