0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/caddyhttp/proxy/setup.go

32 lines
680 B
Go
Raw Normal View History

2016-06-05 22:51:56 -05:00
package proxy
import (
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
func init() {
caddy.RegisterPlugin("proxy", caddy.Plugin{
2016-06-05 22:51:56 -05:00
ServerType: "http",
Action: setup,
})
}
// setup configures a new Proxy middleware instance.
func setup(c *caddy.Controller) error {
upstreams, err := NewStaticUpstreams(c.Dispenser, httpserver.GetConfig(c).Host())
2016-06-05 22:51:56 -05:00
if err != nil {
return err
}
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
2016-06-05 22:51:56 -05:00
return Proxy{Next: next, Upstreams: upstreams}
})
// Register shutdown handlers.
for _, upstream := range upstreams {
c.OnShutdown(upstream.Stop)
}
2016-06-05 22:51:56 -05:00
return nil
}