1.0.4 • Published 4 years ago

ui5-middleware-route v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

JavaScript Style Guide

ui5-middleware-route

Custom UI5 middleware extension for routing http requests using request and static requests using serve-static with http basic authentication support.

For routing requests from a local development enviroment and/or serving ui5/odata/library resources from a remote host/static sources on your system.

Prerequisites

Make sure your project is using the latest UI5 Tooling.

Getting started

Install

Custom middleware

Add the custom middleware as a devDependency to your project.

With yarn:

yarn add -D ui5-middleware-route

Or npm:

npm i -D ui5-middleware-route

Additionally the custom task needs to be manually defined as a ui5 dependency in your project's package.json:

{
  "ui5": {
    "dependencies": [
      "ui5-middleware-route"
    ]
  }
}

Configure

If baseUrl is specified, the routing will proxy to a remote host. If not specified, it will route to a static source.

Custom middleware

Multiple sample configurations below. Register the custom task in your project's ui5.yaml:

server:
  customMiddleware:
    # Remote host routing for ui5 resources
    - name: ui5-middleware-route
      mountPath: /resources
      beforeMiddleware: compression
      configuration:
        baseUrl: https://ui5.sap.com
        path: /resources
    # Static source routing for ui5 resources
    - name: ui5-middleware-route
      mountPath: /resources
      beforeMiddleware: compression
      configuration:
        path: Y:/Development/sapui5/rt/resources         
    # Remote host routing for ui5 test resources
    - name: ui5-middleware-route
      mountPath: /test-resources
      beforeMiddleware: compression
      configuration:
        baseUrl: http://localhost:8080
        path: /test-resources
    # Remote host routing with http basic authentication. (If migrating from Web IDE, you can refer to the paths in neo-app.json) 
    - name: ui5-middleware-route
      mountPath: /sap/opu/odata/
      beforeMiddleware: compression
      configuration:
        debug: true
        baseUrl: http://companytesturl:8001
        path: /sap/opu/odata/
        secure: false
        auth:
          user: userTest
          pass: passTest       
    # Remote host routing for custom SAPUI5 Libraries deployed in Gateway       
    - name: ui5-middleware-route
      mountPath: /sap/bc/ui5_ui5
      beforeMiddleware: compression
      configuration:
        debug: true
        baseUrl: http://companytesturl:8001
        path: /sap/bc/ui5_ui5
        secure: false
        auth:
          user: userTest
          pass: passTest      
    # Static source routing for custom Local UI5 Library resources  
    - name: ui5-middleware-route
      mountPath: /resources/companytest
      beforeMiddleware: compression    
      configuration:
        path: /Users/Me/Desktop/Development/companytest-sapui5-library/src/companytest                            

Additional configuration

Environment file is supported. Define an .env file with your username and password:

UI5_ROUTE_USER=<username>
UI5_ROUTE_PASSWORD=<password>

If this is defined, you can omit the auth object above in your ui5.yaml

You can also define the UI5_ROUTE_BASEURL variable for your baseUrl config:

UI5_ROUTE_BASEURL=http://companytesturl:8001
    - name: ui5-middleware-route
      mountPath: /sap/opu/odata/
      beforeMiddleware: compression
      configuration:
        debug: true
        baseUrl: UI5_ROUTE_BASEURL
        path: /sap/opu/odata/
        secure: false

Options

The custom middleware accepts the following configuration options

nametypeDescriptionmandatorydefaultexamples
debugbooleanenable/disable debug logsnofalsetrue, false
baseUrlstringbaseUrl for proxying requestsyes-https://services.odata.org, http://localhost:8080
pathstringpath for routing requestsno//resources, /V2/Northwind/Northwind.svc
securebooleanreject self-signed certificatesnotruetrue, false
authobjectcredentials for http basic authenticationno-
auth.userstringuser for http basic authenticationno-userTest
auth.passstringpassword for http basic authenticationno-userTest