V2 hard to make it right

Caddy sorts directives according to this predetermined directive order:

You’ll notice that reverse_proxy is ordered higher than file_server, so it will always take precedence, unless you override the order in one of multiple different ways.

I recommend using handle blocks to do this:

http://localhost {
	handle /upload/* {
		root ./svelte/dist
		file_server browse
	}

	handle /api/* {
		reverse_proxy 127.0.0.1:9090
	}

	handle {
		reverse_proxy 127.0.0.1:3000
	}
}

The handle directive allows you to define mutually exclusive request handling blocks (only the first matching handle will be run, ordered by their matchers).

1 Like