UI5 simple proxy middleware
npm install ui5-middleware-simpleproxyMiddleware for ui5-server, enabling proxy support.
- Requires at least @ui5/cli@3.0.0 (to support specVersion: "3.0")
> :warning: UI5 CLI Compatibility
> All releases of this UI5 CLI extension using the major version 3 require UI5 CLI V3. Any previous releases below major version 3 (if available) also support older versions of the UI5 CLI. But the usage of the latest UI5 CLI is strongly recommended!
``bash`
npm install ui5-middleware-simpleproxy --save-dev
)- baseUri: stringUI5_MIDDLEWARE_SIMPLE_PROXY_BASEURI
The baseUri to proxy. Can also be set using the environment variable. To proxy WebSockets just use a WebSocket URL, e.g. ws://echo.websocket.org. Hint: the mountPath of the middleware is not considered for the baseUri. It's just used as is!strictSSL
- : booleantrue
Ignore strict SSL checks. Default value . Can also be set using the UI5_MIDDLEWARE_SIMPLE_PROXY_STRICT_SSL environment variable.removeETag
- : booleanusername
Removes the ETag header from the response to avoid conditional requests.
- : stringpassword
Username used for Basic Authentication.
- : stringhttpHeaders
Password used for Basic Authentication.
- : mapquery
Http headers set for the proxied request. Will overwrite the http headers from the request.
- : mapexcludePatterns
Query parameters set for the proxied request. Will overwrite the parameters from the request.
- : string[]skipCache
Array of exclude patterns using glob syntax
- : booleanenableWebSocket
Remove the cache guid when serving from the FLP launchpad if it matches an excludePattern
- : , default: false experimental
enables support for proxying web sockets
In general, use of environment variables or values set in a .env file will override configuration values in the ui5.yaml.
1. Define the dependency in $yourapp/package.json:
`json`
"devDependencies": {
// ...
"ui5-middleware-simpleproxy": "*"
// ...
}
2. configure it in $yourapp/ui5.yaml:
`yaml`
server:
customMiddleware:
- name: ui5-middleware-simpleproxy
afterMiddleware: compression
mountPath: /odata
configuration:
baseUri: "https://services.odata.org"
username: myUsername
password: myPassword
httpHeaders:
Any-Header: AnyHeader
query:
sap-client: '206'
excludePatterns:
- "/local/**"
The middleware launches a simple proxy-server which proxies the requests to the given uri. Internally, it uses the express proxy middleware.
In case you are using HTTPS and self-signed certificates, you may see an error as displayed below:
`bash`
Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1321:34)
at TLSSocket.emit (events.js:210:5)
at TLSSocket._finishInit (_tls_wrap.js:794:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:608:12)
To avoid it, you can set the strictSSL value in proxy request to be false. Its default value is true.
`yaml`
server:
customMiddleware:
- name: ui5-middleware-simpleproxy
afterMiddleware: compression
mountPath: /odata
configuration:
baseUri: "http://services.odata.org"
strictSSL: false
This plugin supports use of a .env file to declare environment variable values for configuration as described above. The file should be put in the same directory where you run ui5 build, ui5 serve, etc. The file might have contents like:
`shell`
UI5_MIDDLEWARE_SIMPLE_PROXY_BASEURI=https://host.tld:1234/sap
UI5_MIDDLEWARE_SIMPLE_PROXY_STRICT_SSL=false
UI5_MIDDLEWARE_SIMPLE_PROXY_USERNAME=myUsername
UI5_MIDDLEWARE_SIMPLE_PROXY_PASSWORD=myPassword
If you are using the Microsoft OData services for testing purposes, like Northwind for V2 or TripPin for V4, please ensure to use the https URLs instead of the http URLs. The http URL will redirect to https but instead of the proxy it will try to directly connect to the Microsoft OData services.
Another known issue is the the validation of the csrf-token fails for the $batch requests (e.g. in Chrome). To workaround this issue, also running the dev server in https can solve the issue.
UI5 CLI supports running the dev server in https by running the following command line option:
`sh`
ui5 serve --h2
Note: With Node v24, usage of HTTP/2 is no longer supported in UI5 CLI. Please check https://github.com/UI5/cli/issues/327 for updates.
More details can be found in the documentation of the UI5 CLI for the ui5 serve` command.
This work is dual-licensed under Apache 2.0 and the Derived Beer-ware License. The official license will be Apache 2.0 but finally you can choose between one of them if you use this work.
When you like this stuff, buy @vobu a beer or buy @pmuessig a coke when you see them.