@w01f-o/next-middleware-combiner
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Next Middleware Combiner

npm download npm version License

A lightweight library for combining middlewares in Next.js applications. This library allows you to easily compose multiple middlewares into one, making middleware handling in your Next.js project more efficient and manageable.

Features

  • Combine multiple Next.js middlewares into a single middleware.
  • Lightweight and minimalistic design.
  • Fully written in TypeScript with type definitions included.
  • Supports both ESM and CommonJS formats.

Installation

# Using yarn
> yarn add @w01f-o/next-middleware-combiner
# Using npm
> npm install @w01f-o/next-middleware-combiner

Usage

Combining Middlewares

To combine multiple middlewares, simply import the combineMiddlewares function and provide an array of your middlewares.

Example:

import { combineMiddlewares } from '@w01f-o/next-middleware-combiner';
import type { MiddlewareFactory } from '@w01f-o/next-middleware-combiner';

// Middleware 1
const middleware1: MiddlewareFactory = (next) => {
  return (req, res) => {
    console.log('Middleware 1');
    
    return next(req, res);
  };
};

// Middleware 2
const middleware2: MiddlewareFactory = (next) => {
  return (req, res) => {
    console.log('Middleware 2');
    
    return next(req, res);
  };
};

// Combine middlewares
export default combineMiddlewares([middleware1, middleware2]);

export const config = {
  matcher: [
    '/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|.*\\.svg|.*\\.gif).*)',
  ],
};

License

MIT License

Package Sidebar

Install

npm i @w01f-o/next-middleware-combiner

Weekly Downloads

5

Version

0.1.2

License

MIT

Unpacked Size

5.42 kB

Total Files

6

Last publish

Collaborators

  • w01f-o