Rewrite static URL dynamically

1. The problem I’m having:

I am trying to provide a container for the web application of my colleagues. They need to have access to the current configuration of the application by going to https://<host>/configuration.json. The path /configuration.json would then be mapped to a specific file /app/configuration.APP_ENV.json where APP_ENV is an environment variable available in the container.

2. Error messages and/or full log output:

Currently no logs, I’m opening this thread to have some insights on how to do that.

3. Caddy version:

Caddy 2 from the official Docker hub (caddy:2-alpine).

4. How I installed and ran Caddy:

I use a custom container running with Podman. The last line of my Containerfile is CMD [ "caddy", "run", "--config", "/etc/caddy/Caddyfile" ] where the Caddyfile is copied from my local project into the image: COPY resources/environment/Caddyfile /etc/caddy/Caddyfile

a. System environment:

Podman

b. Command:

podman run -ti --rm -e APP_ENV=dev -p 8080:80 app-frontend:latest

d. My complete Caddy config:

:80 {
	root * /app

	handle_path /configuration.json {
		root /app/environment/{env.APP_ENV}.json
		file_server
	}

	try_files {path} {path}/ /index.html
	file_server
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.