CORS is typically an application layer issue. You should configure somekind of CORS middleware in your Django backend. That’s usually a pretty trivial thing to do on the backend.
FWIW, I’d write your config like this:
:{$PORT} {
encode gzip
handle /api* {
reverse_proxy localhost:8000
}
handle {
root * /var/www/html
try_files {path} /index.html
file_server
}
}
Small thing, I’d just always use port 80 inside the container (if you’re not having Caddy handle TLS). You can set up a port mapping from whatever port to 80 in your Docker setup. That way it’s predictable how to reach your Caddy container from another container if necessary.
The problem here is that localhost
inside a container means “this same container”. If you need to proxy to another container, you need to use that container’s name.
So like reverse_proxy django:8000
or whatever.