Skip to content

Latest commit

 

History

History
133 lines (100 loc) · 5.27 KB

File metadata and controls

133 lines (100 loc) · 5.27 KB

UI5 simple proxy middleware

Middleware for ui5-server, enabling proxy support.

Prerequisites

⚠️ UI5 Tooling Compatibility All releases of this tooling extension using the major version 3 require UI5 Tooling V3. Any previous releases below major version 3 (if available) also support older versions of the UI5 Tooling. But the usage of the latest UI5 Tooling is strongly recommended!

Install

npm install ui5-middleware-simpleproxy --save-dev

Configuration options (in $yourapp/ui5.yaml)

  • baseUri: string The baseUri to proxy. Can also be set using the UI5_MIDDLEWARE_SIMPLE_PROXY_BASEURI 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: boolean Ignore strict SSL checks. Default value true. Can also be set using the UI5_MIDDLEWARE_SIMPLE_PROXY_STRICT_SSL environment variable.
  • removeETag: boolean Removes the ETag header from the response to avoid conditional requests.
  • username: string Username used for Basic Authentication.
  • password: string Password used for Basic Authentication.
  • httpHeaders: map Http headers set for the proxied request. Will overwrite the http headers from the request.
  • query: map Query parameters set for the proxied request. Will overwrite the parameters from the request.
  • excludePatterns: string[] Array of exclude patterns using glob syntax
  • skipCache: boolean Remove the cache guid when serving from the FLP launchpad if it matches an excludePattern
  • enableWebSocket: <boolean>, 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.

Usage

  1. Define the dependency in $yourapp/package.json:
"devDependencies": {
    // ...
    "ui5-middleware-simpleproxy": "*"
    // ...
}
  1. 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=myPassword

Hints

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.

The UI5 tooling supports running the dev server in https by running the following command line option:

ui5 serve --h2

More details can be found in the documentation of the UI5 tooling 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.