fix url proxy

This commit is contained in:
Asim Aslam
2021-05-18 17:09:25 +01:00
parent 7dbc9323d6
commit bb892b5f01

View File

@@ -40,13 +40,11 @@ func Handler(w http.ResponseWriter, r *http.Request) {
Path: r.URL.Path,
}
header := make(http.Header)
apiURL := APIHost + "/url/proxy"
// use /v1/
if len(APIKey) > 0 {
apiURL = APIHost + "/v1/url/proxy"
header.Set("Authorization", "Bearer "+APIKey)
}
// make new request
@@ -55,6 +53,16 @@ func Handler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
if req.Header == nil {
req.Header = make(http.Header)
}
// set the api key after we're given the header
if len(APIKey) > 0 {
req.Header.Set("Authorization", "Bearer "+APIKey)
}
// call the backend for the url
rsp, err := http.DefaultClient.Do(req)
if err != nil {