Getting the full server config from a module?

Is it possible to get the entire server config from a module? I’ve been just http.NewRequest(“localhost:2019/config”) but this seems super hacky.

I don’t think there’s an API for that. Modules shouldn’t be manipulating the config directly, really.

What are you trying to do, exactly?

1 Like

I just wanted to print it out for the admin, without having them have to change ports. I have auth on the module already, so it’s pretty straightforward. And it’s not just about the caddyfile output, i’m adding other env variables in there as well.

I’m still not clear on what your goal is here. We’re lacking context.

Getting the config from the admin endpoint seems perfectly fine :man_shrugging:

1 Like

Yeah, I would just do GET http://localhost:2019/config/ (you can enable remote access and add auth as well).

1 Like

Oh it’s fine - I just thought since caddy likely has this structure parsed and in memory (since the server is running) there’d be an internal API for it :slight_smile:


If you’re in an HTTP handler and want the HTTP server, you can get the value from the context using caddyhttp.ServerCtxKey as the key.

Or you can call .App() from the caddy.Context to get a specific app module. But there’s no other programmatic way to get the entire config that I recall.

1 Like