Skip to main content

Minimalistic middleware framework.

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
88%
Published
10 hours ago (1.0.3)

@marianmeres/midware

Minimalistic middleware framework.

JSR

Installation

deno

deno add jsr:@marianmeres/midware

nodejs

npx jsr add @marianmeres/midware

Usage

import { Midware } from '@marianmeres/midware';

Basic example

const app = new Midware<T>();

// Register middlewares via the `use` method. Pass in a non-zero timeout value to watch 
// (and possibly reject) the middleware's execution duration.
app.use(async (context: T) => {
    // do the work here...
    context.foo = 'bar';
    // To break the execution chain return the `Midware.TERMINATE` symbol.
    // If so, no other middleware will execute after this one.
    // return Midware.TERMINATE;
}, timeout = 0);

// Now, execute all registered middlewares in series.
// Pass in a non-zero timeout value to watch (and possibly reject)
// the overall execution duration.
const result = await app.execute({ foo: null }, timeout = 0);

// `result` is the context
assert(result.foo === 'bar');

Add Package

deno add jsr:@marianmeres/midware

Import symbol

import * as midware from "@marianmeres/midware";

---- OR ----

Import directly with a jsr specifier

import * as midware from "jsr:@marianmeres/midware";

Add Package

npx jsr add @marianmeres/midware

Import symbol

import * as midware from "@marianmeres/midware";

Add Package

yarn dlx jsr add @marianmeres/midware

Import symbol

import * as midware from "@marianmeres/midware";

Add Package

pnpm dlx jsr add @marianmeres/midware

Import symbol

import * as midware from "@marianmeres/midware";

Add Package

bunx jsr add @marianmeres/midware

Import symbol

import * as midware from "@marianmeres/midware";