Build with Environment variables with caddy and docker that can access with reactJs app

Please use the latest version, v2.7.6

This is redundant, the Caddy image already does this.

Either way, EXPOSE doesn’t actually do anything, it’s essentially just a documentation/marker.

This doesn’t make sense. You shouldn’t configure tls for an :80 site.

I would rewrite it like this:

	handle /api* {
		reverse_proxy iamge-name-backend:5300
	}

	handle {
		root * /srv
		try_files {path} {path}/ /index.html
		file_server
	}

You’re not actually using this in your config. Snippets don’t do anything unless you import them somewhere.

Anyway, are you sure you need it?

That doesn’t have to do with Caddy, no.

Are you using Vite or something to build? If so you need to use import.meta.env.VAR I think. See the documentation for your build tool.

If you’re writing a NodeJS server app (not frontend JS), then process.env.VAR is what you’d use.

Correct, env vars are replaced at build time in your transpiled JS code. Unrelated to Caddy.

1 Like