Fix workflow apiserver proxy (#363)
This commit is contained in:
committed by
Soam Vasani
parent
0537c4b805
commit
59c18693fa
+2
-2
@@ -69,7 +69,7 @@ func MakeAPI() (*API, error) {
|
|||||||
if len(u) > 0 {
|
if len(u) > 0 {
|
||||||
api.workflowApiUrl = strings.TrimSuffix(wfEnv, "/")
|
api.workflowApiUrl = strings.TrimSuffix(wfEnv, "/")
|
||||||
} else {
|
} else {
|
||||||
api.workflowApiUrl = "http://workflow-apiserver"
|
api.workflowApiUrl = "http://workflows-apiserver"
|
||||||
}
|
}
|
||||||
|
|
||||||
return api, err
|
return api, err
|
||||||
@@ -178,7 +178,7 @@ func (api *API) Serve(port int) {
|
|||||||
r.HandleFunc("/proxy/storage/v1/archive", api.StorageServiceProxy)
|
r.HandleFunc("/proxy/storage/v1/archive", api.StorageServiceProxy)
|
||||||
r.HandleFunc("/proxy/buildermgr/v1/build", api.BuilderManagerBuildProxy)
|
r.HandleFunc("/proxy/buildermgr/v1/build", api.BuilderManagerBuildProxy)
|
||||||
r.HandleFunc("/proxy/buildermgr/v1/builder", api.BuilderManagerEnvBuilderProxy)
|
r.HandleFunc("/proxy/buildermgr/v1/builder", api.BuilderManagerEnvBuilderProxy)
|
||||||
r.HandleFunc("/proxy/workflow", api.WorkflowApiProxy)
|
r.HandleFunc("/proxy/workflows-apiserver/{path:.*}", api.WorkflowApiserverProxy)
|
||||||
|
|
||||||
address := fmt.Sprintf(":%v", port)
|
address := fmt.Sprintf(":%v", port)
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,27 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (api *API) WorkflowApiProxy(w http.ResponseWriter, r *http.Request) {
|
func (api *API) WorkflowApiserverProxy(w http.ResponseWriter, r *http.Request) {
|
||||||
u := api.storageServiceUrl
|
u := api.workflowApiUrl
|
||||||
ssUrl, err := url.Parse(u)
|
ssUrl, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("Error parsing url %v: %v", u, err)
|
msg := fmt.Sprintf("Error parsing url %v: %v", u, err)
|
||||||
http.Error(w, msg, 500)
|
http.Error(w, msg, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
path := fmt.Sprintf("/%s", vars["path"])
|
||||||
director := func(req *http.Request) {
|
director := func(req *http.Request) {
|
||||||
req.URL.Scheme = ssUrl.Scheme
|
req.URL.Scheme = ssUrl.Scheme
|
||||||
req.URL.Host = ssUrl.Host
|
req.URL.Host = ssUrl.Host
|
||||||
req.URL.Path = strings.TrimPrefix(ssUrl.Path, "/proxy/workflow")
|
req.URL.Path = path
|
||||||
req.URL.RawQuery = ssUrl.RawQuery
|
|
||||||
}
|
}
|
||||||
proxy := &httputil.ReverseProxy{
|
proxy := &httputil.ReverseProxy{
|
||||||
Director: director,
|
Director: director,
|
||||||
|
|||||||
Reference in New Issue
Block a user