1.1.2 • Published 2 years ago

@nextwrappers/core v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Next.js Wrappers Core

Create wrappers for Next.js Route Handler and Middleware.

Installation

npm install @nextwrappers/core # npm
yarn add @nextwrappers/core # yarn
pnpm add @nextwrappers/core # pnpm

Usage

Routes

// api/hello/route.ts
import { wrapper } from "@nextwrappers/core";
import { NextRequest, NextResponse } from "next/server";

const hello = wrapper((next, req: NextRequest) => {
  console.log(`Hello '${req.nextUrl.pathname}'!`);
  const res = next();
  console.log(`Bye '${req.nextUrl.pathname}'!`);
  return res;
});

export default hello((req) => {
  return NextResponse.json({ message: "hello" });
});

Middleware

// api/hello/middleware.ts
import { wrapperM } from "@nextwrappers/core";
import { NextRequest, NextResponse } from "next/server";

const hello = wrapperM(async (next, req: NextRequest) => {
  console.log(`Hello '${req.nextUrl.pathname}'!`);
  const res = await next();
  console.log(`Bye '${req.nextUrl.pathname}'!`);
  return res;
});

export default hello((req) => {
  return NextResponse.next();
});

API

  • wrapper(), wrapperM() - For creating Route Handler/Middleware wrappers.
  • stack(), stackM() - For creating a stack of Route Handler/Middleware wrappers.
  • chain(), chainM() - For creating a chain of Route Handler/Middleware wrappers.
  • merge(), mergeM() - For merging two Route Handler/Middleware wrappers.

See more in Features.

Use-Cases 📝

See more in Use-Cases.

Also see Using 3rd-Party Route Handlers for use with route handlers from libraries.

1.1.2

2 years ago

1.1.2-rc6

2 years ago

1.1.2-rc5

2 years ago

1.1.2-rc4

2 years ago

1.1.2-rc3

2 years ago

1.1.2-rc2

2 years ago

1.1.2-rc1

2 years ago

1.1.1

2 years ago

1.1.1-rc2

2 years ago

1.1.1-rc1

2 years ago