diff --git a/.version b/.version index 831446c..ac14c3d 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -5.1.0 +5.1.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a5522..fd4a266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v5.1.1 +* добавлен параметр `withPrefix` в локальном конфиге для `location`, чтобы не обрезать путь при проксировании запроса ### v5.1.0 * обновлены зависимости (увеличены лимиты по семплированию логов, добавлена возможность конфигурировать семплирование) ### v5.0.0 diff --git a/assembly/locator.go b/assembly/locator.go index 90c2dd8..e0381ff 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -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) } diff --git a/conf/config.yml b/conf/config.yml index a41bf7b..2ce41fd 100644 --- a/conf/config.yml +++ b/conf/config.yml @@ -21,7 +21,4 @@ logfile: locations: - pathPrefix: /api protocol: grpc - targetModule: router - - pathPrefix: /mdm - protocol: http - targetModule: mdm-api + targetModule: router \ No newline at end of file diff --git a/conf/local.go b/conf/local.go index 99910a4..5ca0822 100644 --- a/conf/local.go +++ b/conf/local.go @@ -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"` diff --git a/middleware/entrypoint.go b/middleware/entrypoint.go index c163c0c..91cd85c 100644 --- a/middleware/entrypoint.go +++ b/middleware/entrypoint.go @@ -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)