-
Notifications
You must be signed in to change notification settings - Fork 480
/
DashboardRouter.go
44 lines (39 loc) · 1.16 KB
/
DashboardRouter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package router
import (
"fmt"
"github.com/devtron-labs/devtron/client/dashboard"
"github.com/gorilla/mux"
"go.uber.org/zap"
"net"
"net/http"
"time"
)
type DashboardRouter interface {
initDashboardRouter(router *mux.Router)
}
type DashboardRouterImpl struct {
logger *zap.SugaredLogger
dashboardProxy func(writer http.ResponseWriter, request *http.Request)
}
func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *dashboard.Config) *DashboardRouterImpl {
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}
dashboardProxy := dashboard.NewDashboardHTTPReverseProxy(fmt.Sprintf("http://%s:%s", dashboardCfg.Host, dashboardCfg.Port), client.Transport)
router := &DashboardRouterImpl{
dashboardProxy: dashboardProxy,
logger: logger,
}
return router
}
func (router DashboardRouterImpl) initDashboardRouter(dashboardRouter *mux.Router) {
dashboardRouter.PathPrefix("").HandlerFunc(router.dashboardProxy)
}