Skip to content

Commit

Permalink
add NoAuth option for extrnal proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhashBose authored Sep 14, 2023
1 parent e5a2d81 commit 5ae37e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 5 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ listenAddressSingleHTTPFrontend: 0.0.0.0:1337
# Base url to use for built-in proxy, default is '/'. Can be changed here
#ProxyBaseURL: /control/

# HTTP Basic authentication
# Global HTTP Basic authentication
#AuthUser: user
#AuthPass: password

Expand Down Expand Up @@ -92,4 +92,7 @@ actions:
# Create reverse proxies for given URLs
#externalproxies:
#- target: http://localhost:8975
# baseurl: /application/
# baseurl: /application1/
#- target: http://localhost:2222
# baseurl: /application2/
# noauth: true # exclude from global HTTP authentication if defined in this config
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type AccessControlList struct {
type ExternalProxy struct {
BaseURL string
Target string
NoAuth bool `default:false`
}

// Config is the global config used through the whole app.
Expand Down
20 changes: 10 additions & 10 deletions internal/httpservers/singleFrontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ func StartSingleHTTPFrontend(cfg *config.Config) {
}
})

MakeProxy := func (base, target string) {
appURL, _ := url.Parse(target)
MakeProxy := func (proxy config.ExternalProxy) {
log.Info("Setting up external Proxy: " + proxy.BaseURL + " -> " + proxy.Target)
appURL, _ := url.Parse(proxy.Target)
appProxy := httputil.NewSingleHostReverseProxy(appURL)
mux.HandleFunc(base, func(w http.ResponseWriter, r *http.Request) {
if (!AuthFunc(w,r)) {
return
}
r.URL.Path = strings.Replace(r.URL.Path,base,"/",1)
appProxy.ServeHTTP(w, r)
mux.HandleFunc(proxy.BaseURL, func(w http.ResponseWriter, r *http.Request) {
if (!proxy.NoAuth && !AuthFunc(w,r)) {
return
}
r.URL.Path = strings.Replace(r.URL.Path,proxy.BaseURL,"/",1)
appProxy.ServeHTTP(w, r)
})
}

for _, extproxy := range cfg.ExternalProxies {
log.Info("Setting up external Proxy: " + extproxy.BaseURL + " -> " + extproxy.Target)
MakeProxy(extproxy.BaseURL, extproxy.Target)
MakeProxy(extproxy)
}

srv := &http.Server{
Expand Down

0 comments on commit 5ae37e3

Please sign in to comment.