MSP-1470 add ws in locator
This commit is contained in:
1 parent
cbbc03acb9
commit
02334b3617
2 files changed
+9
-3
No files matched your search
@@ -50,7 +50,7 @@ func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||
return nil, errors.WithMessage(err, "new grpc client")
|
||||
}
|
||||
grpcClientByModuleName[location.TargetModule] = cli
|
||||
case conf.HttpProtocol:
|
||||
case conf.HttpProtocol, conf.WsProtocol:
|
||||
rb := lb.NewRoundRobin(nil)
|
||||
httpHostManagerByModuleName[location.TargetModule] = rb
|
||||
default:
|
||||
|
||||
+8
-2
@@ -64,6 +64,8 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
throttlingRepo := repository.NewThrottling(redisCli)
|
||||
throttlingService := service.NewThrottling(throttlingRepo, config.Throttling)
|
||||
|
||||
enableBodyLog := config.Logging.BodyLogEnable
|
||||
|
||||
mux := http.NewServeMux()
|
||||
for _, location := range locations {
|
||||
var proxyFunc middleware.Handler
|
||||
@@ -74,6 +76,10 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
case conf.HttpProtocol:
|
||||
hostManager := l.httpHostManagerByModuleName[location.TargetModule]
|
||||
proxyFunc = proxy.NewHttp(hostManager, location.SkipAuth, time.Duration(config.Http.ProxyTimeoutInSec)*time.Second)
|
||||
case conf.WsProtocol:
|
||||
hostManager := l.httpHostManagerByModuleName[location.TargetModule]
|
||||
proxyFunc = proxy.NewWs(hostManager, location.SkipAuth)
|
||||
enableBodyLog = false
|
||||
default:
|
||||
return nil, errors.Errorf("not supported protocol %s", location.Protocol)
|
||||
}
|
||||
@@ -81,7 +87,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
handler := middleware.Chain(
|
||||
proxyFunc,
|
||||
middleware.RequestId(),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, config.Logging.BodyLogEnable),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog),
|
||||
middleware.ErrorHandler(l.logger),
|
||||
middleware.Authenticate(authentication),
|
||||
middleware.AdminAuthenticate(adminService),
|
||||
@@ -94,7 +100,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
handler = middleware.Chain(
|
||||
proxyFunc,
|
||||
middleware.RequestId(),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, config.Logging.BodyLogEnable),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog),
|
||||
middleware.ErrorHandler(l.logger),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user