npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sap-ux/serve-static-middleware

v0.1.2

Published

Serve static middleware

Downloads

25

Readme

@sap-ux/serve-static-middleware

The @sap-ux/serve-static-middleware is a Custom UI5 Server Middleware for serving any static resources locally from your machine.

It can be used either with the ui5 serve or the fiori run commands.

Configuration Options

| Option | Type | Description | | ------------ | ------------- | ----------- | | paths | array | List of mount paths and local paths that should be handled by the serve static middleware. | | [option] | string \| number \| boolean | Configuration options of serve-static. Excluding setHeaders! Alternatively you can add each option on a specific path |

Configuration Examples

Serving UI5 locally

Pre-requisites: SAPUI5 SDK version is downloaded and extracted locally on the machine. One can download UI5 resources from https://tools.hana.ondemand.com/#sapui5

Executing ui5 serve in your project with the configuration below in a ui5.yaml file would serve the UI5 sources from your machine. Any request starting with the path parameter will be forwarded to the local path provided in the src parameter.

server:
  customMiddleware:
  - name: serve-static-middleware
    afterMiddleware: compression
    configuration:
      paths:
        - path: /resources
          src: "Path/To/SAPUI5-SDK"
        - path: /test-resources
          src: "Path/To/SAPUI5-SDK"

Serving any type of resources locally

Executing npx fiori run in your project with the configuration below in a ui5.yaml file would serve resources from your machine. Any request starting with the path parameter will be forwarded to the local path provided in the src parameter.

server:
  customMiddleware:
  - name: serve-static-middleware
    afterMiddleware: compression
    configuration:
      paths:
        - path: /images
          src: "Path/To/images"
        - path: /libs
          src: "Path/To/libs"

Mocking the User API Service from @sap/approuter

If you are using the User API Service from @sap/approuter in your application, then you can mock by providing the following configuration.

server:
  customMiddleware:
  - name: serve-static-middleware
    afterMiddleware: compression
    configuration:
      paths:
        - path: /userapi/currentUser
          src: "Path/To/UserJson/user.json"
          index: false
          fallthrough: false
          redirect: false

whereas the user.json can look like this e.g.

{
   "firstname": "John",
   "lastname": "Doe",
   "email": "[email protected]",
   "name": "[email protected]",
   "displayName": "John Doe ([email protected])",
   "scopes": "openid,user_attributes,uaa.user"
}

serve-static configuration options

Additionaly you can specify any of the configuration options (excluding setHeaders!) of the serve-static middleware.

E.g. you can set fallthrough: false, which will cause the middleware to return 404 error, when it can't find a file on the local system:

server:
  customMiddleware:
  - name: serve-static-middleware
    afterMiddleware: compression
    configuration:
      paths:
        - path: /resources
          src: "Path/To/SAPUI5-SDK"
        - path: /test-resources
          src: "Path/To/SAPUI5-SDK"
      fallthrough: false

Alternatively you can set e.g. fallthrough: false only for specific requests:

server:
  customMiddleware:
  - name: serve-static-middleware
    afterMiddleware: compression
    configuration:
      paths:
        - path: /resources
          src: "Path/To/SAPUI5-SDK"
          fallthrough: false
        - path: /test-resources
          src: "Path/To/SAPUI5-SDK"

Programmatic Usage

Alternatively you can only use the underlying middleware function, e.g. for the case when you want to use the serve-static-middleware functionality in your express server.`

import { serveStaticMiddleware } from '@sap-ux/serve-static-middleware';
const serveStaticFn = serveStaticMiddleware(root, config);
  • root - project root directory
  • config - the serve-static-middleware configuration

Keywords

  • Serve Static Middleware
  • Fiori tools
  • Fiori elements
  • SAP UI5