The problem is that I was using caddy to serve httpS, so this was useless.
I finally used this Caddyfile:
<my-domain> { reverse_proxy localhost:3000 handle_path /api/* { reverse_proxy localhost:8000 } }