Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
next-middlewares
Advanced tools
This is a library that can use multiple middlewares in Next.
Next's middleware cannot be configured with multiple middlewares. To solve this problem, we provide a library to allow Next to support multiple middlewares.
next-middlewares
is tested with:
13.0.0
and aboveFirst, install next-middlewares
:
$ npm install next-middlewares
# OR
$ yarn add next-middlewares
# OR
$ pnpm install next-middlewares
The way to define middlewares is almost exactly the same as Next. For details, please refer to the Next document Middleware. The difference is that we only support config.match
, other configurations will be ignored.
For example, you can create a new middlewares
folder and create a new redirection middleware redirect.ts
in it, the code is as follows
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest): Promise<NextResponse> {
return NextResponse.redirect(new URL('/home', request.url))
}
export const config = {
matcher: '/about',
};
Then, we can create a new middleware.ts
file in the app
or src
or pages
directory of the project according to Next's specifications. And reference our middlewares, use createMiddleware
to combine them. Code show as below:
import { createMiddleware, config } from 'next-middlewares';
import * as RedirectMiddleware from './middlewares/redirect';
import * as RSSMiddleware from './middlewares/rss';
export const middleware = createMiddleware([RedirectMiddleware, RSSMiddleware]);
export { config };
That's all there is to it, your app will support multiple middlewares.
FAQs
A library that can use multiple middleware in Next
The npm package next-middlewares receives a total of 5 weekly downloads. As such, next-middlewares popularity was classified as not popular.
We found that next-middlewares demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.