From 58f33f0b123557603415ed7d0fe5fa198126b45d Mon Sep 17 00:00:00 2001 From: mpl Date: Mon, 14 Jan 2013 23:33:49 +0100 Subject: [PATCH] camweb: added reverse proxy for the build bot server Change-Id: I9e1c8b0e2d28f9f7660763ecbd3f8be149dfe716 --- website/camweb.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/website/camweb.go b/website/camweb.go index 260cefcfb..fdd48c0ba 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -52,12 +52,14 @@ var ( tlsKeyFile = flag.String("tlskey", "", "TLS private key file") gerritUser = flag.String("gerrituser", "ubuntu", "Gerrit host's username") gerritHost = flag.String("gerrithost", "", "Gerrit host, or empty.") + buildbotBackend = flag.String("buildbot_backend", "", "Build bot status backend.") + buildbotHost = flag.String("buildbot_host", "", "Hostname to map to the buildbot_backend. If an HTTP request with this hostname is received, it proxies to buildbot_backend.") pageHtml, errorHtml *template.Template ) var fmap = template.FuncMap{ - "": textFmt, - "html": htmlFmt, + "": textFmt, + "html": htmlFmt, "htmlesc": htmlEscFmt, } @@ -321,6 +323,16 @@ func main() { } mux.HandleFunc("/", mainHandler) + if *buildbotHost != "" && *buildbotBackend != "" { + buildbotUrl, err := url.Parse(*buildbotBackend) + if err != nil { + log.Fatalf("Failed to parse %v as a URL: %v", *buildbotBackend, err) + } + buildbotHandler := httputil.NewSingleHostReverseProxy(buildbotUrl) + bbhpattern := strings.TrimRight(*buildbotHost, "/") + "/" + mux.Handle(bbhpattern, buildbotHandler) + } + var handler http.Handler = &noWwwHandler{Handler: mux} if *logDir != "" || *logStdout { handler = NewLoggingHandler(handler, *logDir, *logStdout)