项目作者: negezor

项目描述 :
⛓️ Modern middleware with promises
高级语言: TypeScript
项目地址: git://github.com/negezor/middleware-io.git
创建时间: 2017-10-29T10:29:26Z
项目社区:https://github.com/negezor/middleware-io

开源协议:MIT License

下载




Build Status
NPM version
NPM downloads

Middleware-IO - Modern middleware on Promise

📖 Documentation

Features

  1. Self-Sufficient. The library has zero dependencies.
  2. Reliable. The library is written in TypeScript and covered by tests.
  3. Modern. The library comes with native ESM support
  4. Powerful. Supports following additional features:
    • The library has enough built-in snippets;
    • The middleware chain builder;

Installation

Node.js 12.0.0 or newer is required

  • Using npm (recommended)
    1. npm i middleware-io
  • Using Yarn
    1. yarn add middleware-io
  • Using pnpm
    1. pnpm add middleware-io

Example usage

  1. import { compose } from 'middleware-io';
  2. const composedMiddleware = compose([
  3. async (context, next) => {
  4. // Step 1
  5. await next();
  6. // Step 4
  7. // Print the current date from the next middleware
  8. console.log(context.now);
  9. },
  10. async (context, next) => {
  11. // Step 2
  12. context.now = Date.now();
  13. await next();
  14. // Step 3
  15. }
  16. ]);
  17. composedMiddleware({}, () => { /* Last handler (next) */ })
  18. .then(() => {
  19. console.log('Middleware finished work');
  20. })
  21. .catch(console.error);