Use one single configuration file for prod and dev environments?

You can use import for snippets, and environment variables to do it.

For example:

(frontend) {
	handle /static/frontend/* {
		reverse_proxy node:8000
	}
}

:9000 {
	{$CADDY_EXTRA_DIRECTIVES}

	handle {
		reverse_proxy back:8000
	}

	log
}

Then in your docker-compose config and/or in a .env file, you can put this:

CADDY_EXTRA_DIRECTIVES="import frontend"

And you may leave that environment variable empty if you don’t want the frontend handler to be loaded in the config.

Read about env in docker-compose: Environment variables in Compose | Docker Documentation

See the Caddy docs for snippets and environment variables

3 Likes