ui5-tooling icon indicating copy to clipboard operation
ui5-tooling copied to clipboard

mountPath for middleware is not supporting array or regex

Open piejanssens opened this issue 4 years ago • 4 comments

Expected Behavior

Support arrays for mountPath just like express does

Current Behavior

It's not supported

Steps to Reproduce the Issue

  1. add middleware with array definition for mountPath
    - name: ui5-middleware-simpleproxy
      afterMiddleware: ui5-middleware-stringreplacer
      mountPath:
        - '/ci/'
        - '/v2/'
        - '/sf/'

Context

  • UI5 Module Version (output of ui5 --version when using the CLI): 2.13
  • Node.js Version: 14
  • npm Version: 8.1

Log Output / Stack Trace

Configuration server/customMiddleware/1/mountPath must be of type 'string'

/home/pieter/projects/xxx/app/ui5.yaml:17

15:     - name: ui5-middleware-simpleproxy
16:       afterMiddleware: compression
17:       mountPath:

piejanssens avatar Oct 25 '21 13:10 piejanssens

I tried a regex, but that doesn't seem to be recongized as regex and fails when the path is converted to a regex: mountPath: /\/(ci|v2|sf){1}\/.*/

Stack Trace:
SyntaxError: Invalid regular expression: /^\/\\/(?(?:([^\/]+?))|v2|sf){1}\\/\.(.*)\/?(?=\/|$)/: Invalid group
    at new RegExp (<anonymous>)
    at pathtoRegexp (/home/pieter/projects/xxx/app/node_modules/@ui5/cli/node_modules/path-to-regexp/index.js:128:10)

piejanssens avatar Oct 25 '21 13:10 piejanssens

Sounds reasonable. This is only limited by our schema.

@matz3 can you think of any reasons against allowing arrays and regular expressions here as well?

RandomByte avatar Oct 25 '21 15:10 RandomByte

Also see our documentation:

An optional mountPath for which the middleware function is invoked can be provided. It will be passed to the app.use call (see express API reference).

RandomByte avatar Oct 25 '21 15:10 RandomByte

@RandomByte an array should be fine. I just wonder about a regular expression. YAML/JSON don't support RegExp, so we would need to differentiate between a RegExp pattern and a string or path pattern.

matz3 avatar Oct 27 '21 08:10 matz3