Skip to content

Commit 8be1cfb

Browse files
authored
Merge pull request #36 from alexdln/nmc-35
nmc-35 refactor package and improve next v16 support
2 parents 96f3154 + a801072 commit 8be1cfb

30 files changed

+775
-2387
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Alexander Savelyev <vordgi1@gmail.com>
3+
Copyright (c) 2024 Alex Savelyev <dev@alexdln.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# @nimpl/middleware-chain
1+
# @nimpl/proxy-chain
22

3-
The package allows you to create a chain of native next.js middlewares without any modifications (_i.e., you can add any ready-made middleware to the chain_)
3+
The package allows you to create a chain of native next.js proxies without any modifications (_i.e., you can add any ready-made proxy to the chain_)
44

5-
```ts
6-
// middleware.ts
7-
import { chain } from "@nimpl/middleware-chain";
5+
```ts filename="proxy.ts"
6+
// proxy.ts
7+
import { chain } from "@nimpl/proxy-chain";
88

99
export default chain([
10-
[intlMiddleware, { exclude: /^\/private(\/.*)?$/ }],
11-
authMiddleware,
10+
[intlProxy, { exclude: /^\/private(\/.*)?$/ }],
11+
authProxy,
1212
(req, event) => {
1313
event.waitUntil(
1414
fetch("https://my-analytics-platform.com", {
@@ -18,29 +18,47 @@ export default chain([
1818
);
1919
return NextResponse.next();
2020
},
21-
customMiddleware,
21+
customProxy,
2222
]);
2323
```
2424

25-
Visit https://nimpl.tech/middleware-chain to view the full documentation.
25+
Visit https://nimpl.dev/docs/proxy-chain to view the full documentation.
26+
27+
## Compatibility
28+
29+
The utility is fully compatible with **all versions of Next.js** that support middleware/proxy.
30+
31+
If you're using a version **below 16.0.0**, create a `middleware.ts` instead of `proxy.ts` file:
32+
33+
```ts filename="middleware.ts"
34+
import { chain } from "@nimpl/proxy-chain";
35+
import { NextRequest, NextResponse, NextFetchEvent } from "next/types";
36+
37+
export const middleware = chain<NextRequest, NextResponse, NextFetchEvent>([
38+
// ...
39+
]);
40+
```
41+
42+
> [!TIP]
43+
> Explicitly pass the types NextRequest, NextResponse, and NextFetchEvent as generics to the chain function to ensure proper type safety and autocompletion.
2644
2745
## Installation
2846

2947
**Using npm:**
3048

3149
```bash
32-
npm i @nimpl/middleware-chain
50+
npm i @nimpl/proxy-chain
3351
```
3452

3553
**Using yarn:**
3654

3755
```bash
38-
yarn add @nimpl/middleware-chain
56+
yarn add @nimpl/proxy-chain
3957
```
4058

4159
## Motivation
4260

43-
All existing solutions work through their own APIs - made under the style of express or in their own vision. They are useful, well implemented, and convenient. But only in cases where you can update every used middleware.
61+
All existing solutions work through their own APIs - made under the style of express or in their own vision. They are useful, well implemented, and convenient. But only in cases where you can update every used proxy.
4462

4563
However, there are many situations where you need to add already prepared solutions. Usually, in the issues of these solutions, you can find “support to add a chain package A, working with chain package B”.
4664

@@ -50,12 +68,13 @@ This is not Koa and not Express, this is a package for next.js, in its unique st
5068

5169
## Examples
5270

53-
- [Base example](https://github.com/vordgi/nimpl-middleware-chain/tree/main/examples/base).
54-
- [next-auth + next-intl example](https://github.com/vordgi/nimpl-middleware-chain/tree/main/examples/auth-intl).
71+
- [Base example](https://github.com/alexdln/nimpl-proxy-chain/tree/main/examples/base).
72+
- [next-auth + next-intl example](https://github.com/alexdln/nimpl-proxy-chain/tree/main/examples/auth-intl).
73+
- [next-auth5 + next-intl example](https://github.com/alexdln/nimpl-proxy-chain/tree/main/examples/auth5-intl).
5574

5675
## Development
5776

58-
Read about working on the package and making changes on the contribution page
77+
Read about working on the package and making changes on the [contribution page](https://nimpl.dev/contribution)
5978

6079
## Additional
6180

@@ -65,4 +84,4 @@ Create issues with wishes, ideas, difficulties, etc. All of them will definitely
6584

6685
## License
6786

68-
[MIT](https://github.com/vordgi/nimpl-middleware-chain/blob/main/LICENSE)
87+
[MIT](https://github.com/alexdln/nimpl-proxy-chain/blob/main/LICENSE)

eslint.config.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
22
import tseslint from "typescript-eslint";
33

4-
const ignores = ["**/node_modules/**", "**/dist/**", "**/*.js", "**/*.d.ts"];
4+
const ignores = ["**/node_modules/**", "**/dist/**", "**/.next/**", "**/*.js", "**/*.d.ts"];
55

66
export default [
77
{
@@ -19,4 +19,5 @@ export default [
1919
},
2020
...tseslint.configs.recommended,
2121
eslintPluginPrettierRecommended,
22-
].map((r) => Object.assign(r, { ignores }));
22+
{ ignores },
23+
];

examples/auth-intl/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/.pnp
66
.pnp.js
77
.yarn/install-state.gz
8+
pnpm-lock.yaml
89

910
# testing
1011
/coverage

examples/auth-intl/package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
"scripts": {
66
"dev": "next dev",
77
"build": "next build",
8-
"start": "next start",
9-
"lint": "next lint"
8+
"start": "next start"
109
},
1110
"dependencies": {
12-
"@nimpl/middleware-chain": "0.2.0",
13-
"next": "14.2.3",
11+
"@nimpl/proxy-chain": "latest",
12+
"next": "16.0.0",
1413
"next-auth": "4.24.7",
1514
"next-intl": "3.14.1",
16-
"react": "^18",
17-
"react-dom": "^18"
15+
"react": "19.2.0",
16+
"react-dom": "19.2.0"
1817
},
1918
"devDependencies": {
20-
"@types/node": "^20",
21-
"@types/react": "^18",
22-
"@types/react-dom": "^18",
23-
"typescript": "^5"
19+
"@types/node": "24.9.1",
20+
"@types/react": "19.2.2",
21+
"@types/react-dom": "19.2.2",
22+
"typescript": "5.9.3"
2423
}
2524
}

0 commit comments

Comments
 (0)