Integrate Caddy w/ HttpHandler & Mux?

Hi, I’m a newbie.
I’m trying to figure out how to add HttpHandlers to my running Caddy.

http.Handle("/foo", fooHandler)
log.Fatal(http.ListenAndServe(":8080", nil))

I’m assuming I need to integrate w/ the caddy instance below
instance, err := caddy.Start(caddyfile)

At first I thought I could configure in caddyFile, but didn’t find any examples.
Thinking it’s probably using good old net/http package together w/ caddy instance.

Appreciate any advice and examples!

Found this sample using routing but doesn’t show how to setup rules.
Maybe have some better examples, that are easier to learn from?

Hi @Basile_Alex, welcome to the Caddy community.

Looks like you’re trying to extend Caddy with middleware! You can find the documentation on how to do that here:

Give that wiki page a read and look further into the pages for Directives and HTTP Middleware, which outline the methods used by the header code you linked.

I should note that Caddy doesn’t use or directly integrate with another net/http server, though. Depending on what your server does, instead of extending with middleware, you could run your Caddy instance with a proxy directive to your own server listening on a local port.

Thanks Whitestrake. I will proxy instead

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