使用 proxy 中间件可以让开发人员通过配置的方式连接不同的后台系统,或者是切换不同的 SAP UI5 版本。
下面是一个典型的 ui5.yaml 里的 proxy 配置文件的例子:
- name: fiori-tools-proxy afterMiddleware: compression configuration: backend: - path: /sap url: https://my.backend.com:1234
这个配置的语义是,该 SAP UI5 应用启动之后,凡是发送到 /sapXXX 路径的 OData 请求,都会被自动转发到 url 指定的后台服务器去。
为了使上述 ui5.yaml 生效,需要使用命令行 npx fiori run 启动本地 SAP UI5 应用。
如果需要通过 destination 连接到后台系统(这是 SAP UI5 应用部署到 SAP BTP 平台 CloudFoundry 环境的常见需求),只需要在 ui5.yaml 里增添 Destination 字段的维护:
- name: fiori-tools-proxy afterMiddleware: compression configuration: backend: - path: /sap url: https://my.backend.com:1234 destination: my_backend
连接多个后台系统的配置语法:
- name: fiori-tools-proxy afterMiddleware: compression configuration: backend: - path: /northwind url: https://my.backend_2.com:1234 - path: /sap url: https://my.backend.com:1234
连接 SAP API Hub 的语法:
- name: fiori-tools-proxy afterMiddleware: compression configuration: backend: - path: /s4hanacloud url: https://api.sap.com apiHub: true
相应的,如果是连接 SAP BTP ABAP 编程环境,加上如下的键值对:
scp: true
可以通过配置的方式,指定任意的 SAP UI5 版本号:
- name: fiori-tools-proxy afterMiddleware: compression configuration: ui5: path: - /resources - /test-resources url: https://sapui5.hana.ondemand.com version: 1.78.0
让 SAP UI5 使用本地库文件的做法:
server: customMiddleware: - name: fiori-tools-servestatic afterMiddleware: compression configuration: paths: - path: /resources src: "Path/To/SAPUI5-SDK" - path: /test-resources src: "Path/To/SAPUI5-SDK"
如果想加载静态图片:
server: customMiddleware: - name: fiori-tools-servestatic afterMiddleware: compression configuration: paths: - path: /images src: "Path/To/images" - path: /libs src: "Path/To/libs"
fiori-tools-servestatic 是一个 Node.js 包,用于为 SAP Fiori 应用程序提供静态文件服务。SAP Fiori 是一组基于 SAPUI5 的应用程序,用于简化和优化用户与 SAP 解决方案的交互。这些应用程序的前端资源(如 JavaScript、HTML 和 CSS 文件)通常需要通过 HTTP 服务器进行服务。
fiori-tools-servestatic 包的作用是在本地开发环境中为这些静态资源提供一个简单的 HTTP 服务器,使开发人员能够运行和测试他们的 Fiori 应用程序。这个包可以作为一个单独的命令行工具使用,也可以与其他 Fiori 工具一起使用,例如 @sap-ux/fiori-tools-proxy,它提供了一个代理服务器来处理与后端系统的通信。