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?
https://github.com/mholt/caddy/blob/e42c6bf0bb00d2e5e966ec7d9923eb21627a6b74/middleware/headers/headers.go#L24
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: https://github.com/mholt/caddy/wiki/Extending-Caddy
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