Merge branch 'MSP-2684' into 'master'
MSP-2684 See merge request integration-system/isp-gate-service!16
This commit is contained in:
commit
56d3e06e49
6 files changed
+20
-10
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v5.1.1
|
||||
* добавлен параметр `withPrefix` в локальном конфиге для `location`, чтобы не обрезать путь при проксировании запроса
|
||||
### v5.1.0
|
||||
* обновлены зависимости (увеличены лимиты по семплированию логов, добавлена возможность конфигурировать семплирование)
|
||||
### v5.0.0
|
||||
|
||||
+4
-2
@@ -111,12 +111,14 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
middleware.ErrorHandler(l.logger),
|
||||
)
|
||||
}
|
||||
|
||||
entrypoint := middleware.Entrypoint(
|
||||
config.Http.MaxRequestBodySizeInMb*1024*1024, //nolint:gomnd
|
||||
handler,
|
||||
location.PathPrefix,
|
||||
l.logger,
|
||||
middleware.EntryPointConfig{
|
||||
WithPrefix: location.WithPrefix,
|
||||
PathPrefix: location.PathPrefix,
|
||||
},
|
||||
)
|
||||
mux.PathPrefix(location.PathPrefix).Handler(entrypoint)
|
||||
}
|
||||
|
||||
+1
-4
@@ -21,7 +21,4 @@ logfile:
|
||||
locations:
|
||||
- pathPrefix: /api
|
||||
protocol: grpc
|
||||
targetModule: router
|
||||
- pathPrefix: /mdm
|
||||
protocol: http
|
||||
targetModule: mdm-api
|
||||
targetModule: router
|
||||
@@ -11,6 +11,7 @@ type Local struct {
|
||||
}
|
||||
|
||||
type Location struct {
|
||||
WithPrefix bool
|
||||
SkipAuth bool
|
||||
PathPrefix string `validate:"required"`
|
||||
Protocol string `validate:"required,oneof=http grpc ws"`
|
||||
|
||||
@@ -10,12 +10,20 @@ import (
|
||||
"isp-gate-service/request"
|
||||
)
|
||||
|
||||
func Entrypoint(maxReqBodySize int64, next Handler, pathPrefix string, logger log.Logger) http.Handler {
|
||||
type EntryPointConfig struct {
|
||||
PathPrefix string
|
||||
WithPrefix bool
|
||||
}
|
||||
|
||||
func Entrypoint(maxReqBodySize int64, next Handler, logger log.Logger, cfg EntryPointConfig) http.Handler {
|
||||
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
|
||||
req.Body = http.MaxBytesReader(writer, req.Body, maxReqBodySize)
|
||||
|
||||
prefix := fmt.Sprintf("%s/", pathPrefix)
|
||||
endpoint := strings.TrimPrefix(req.URL.Path, prefix)
|
||||
endpoint := req.URL.Path
|
||||
if !cfg.WithPrefix {
|
||||
prefix := fmt.Sprintf("%s/", cfg.PathPrefix)
|
||||
endpoint = strings.TrimPrefix(req.URL.Path, prefix)
|
||||
}
|
||||
ctx := request.NewContext(req, writer, endpoint)
|
||||
|
||||
err := next.Handle(ctx)
|
||||
|
||||
Reference in new issue
Block a user