ui5-middleware-simpleproxy
v3.6.0
Published
UI5 simple proxy middleware
Downloads
80,732
Readme
UI5 simple proxy middleware
Middleware for ui5-server, enabling proxy support.
Prerequisites
- Requires at least
@ui5/[email protected](to supportspecVersion: "3.0")
:warning: UI5 CLI Compatibility All releases of this UI5 CLI extension using the major version
3require UI5 CLI V3. Any previous releases below major version3(if available) also support older versions of the UI5 CLI. But the usage of the latest UI5 CLI is strongly recommended!
Install
npm install ui5-middleware-simpleproxy --save-devConfiguration options (in $yourapp/ui5.yaml)
baseUri:stringThe baseUri to proxy. Can also be set using theUI5_MIDDLEWARE_SIMPLE_PROXY_BASEURIenvironment variable. To proxy WebSockets just use a WebSocket URL, e.g.ws://echo.websocket.org. Hint: themountPathof the middleware is not considered for the baseUri. It's just used as is!strictSSL:booleanIgnore strict SSL checks. Default valuetrue. Can also be set using theUI5_MIDDLEWARE_SIMPLE_PROXY_STRICT_SSLenvironment variable.removeETag:booleanRemoves the ETag header from the response to avoid conditional requests.username:stringUsername used for Basic Authentication.password:stringPassword used for Basic Authentication.httpHeaders:mapHttp headers set for the proxied request. Will overwrite the http headers from the request.query:mapQuery parameters set for the proxied request. Will overwrite the parameters from the request.excludePatterns:string[]Array of exclude patterns using glob syntaxskipCache:booleanRemove the cache guid when serving from the FLP launchpad if it matches an excludePatternenableWebSocket:<boolean>, default:falseexperimental 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.
Usage
- Define the dependency in
$yourapp/package.json:
"devDependencies": {
// ...
"ui5-middleware-simpleproxy": "*"
// ...
}- configure it in
$yourapp/ui5.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/**"How it works
The middleware launches a simple proxy-server which proxies the requests to the given uri. Internally, it uses the express proxy middleware.
How to ignore self-signed certificates?
In case you are using HTTPS and self-signed certificates, you may see an error as displayed below:
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.
server:
customMiddleware:
- name: ui5-middleware-simpleproxy
afterMiddleware: compression
mountPath: /odata
configuration:
baseUri: "http://services.odata.org"
strictSSL: false.env support
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:
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=myPasswordHints
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:
ui5 serve --h2Note: 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.
License
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.
