next-ssr-middleware 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReadMe.md +8 -7
- package/dist/API.d.ts +4 -4
- package/dist/API.js +2 -2
- package/dist/API.js.map +1 -1
- package/dist/SSR/shim.js +39 -34
- package/dist/SSR/shim.js.map +1 -1
- package/package.json +17 -18
- package/source/API.ts +13 -8
- package/source/SSR/shim.ts +5 -2
package/ReadMe.md
CHANGED
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
|
|
10
10
|
## Versions
|
|
11
11
|
|
|
12
|
-
| SemVer
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
| `>=0.
|
|
17
|
-
|
|
|
12
|
+
| SemVer | status | Next.js | MobX | [MobX i18n][6] | Koa |
|
|
13
|
+
| :-----------: | :----------: | :-------: | :---------: | :------------: | :---: |
|
|
14
|
+
| `>=1` | ✅developing | `>=15` | ❌ | ❌ | `3.x` |
|
|
15
|
+
| `>=0.10 <1` | ❌deprecated | `>=15` | `>=6.11` | `>=0.5` | `2.x` |
|
|
16
|
+
| `>=0.9 <0.10` | ✅developing | `>=15` | `>=6.11` | `>=0.5` | ❌ |
|
|
17
|
+
| `>=0.7 <0.9` | ❌deprecated | `>=9 <15` | `>=6.11` | `>=0.5` | ❌ |
|
|
18
|
+
| `<0.7` | ❌deprecated | `>=9 <15` | `>=4 <6.11` | `<0.5` | ❌ |
|
|
18
19
|
|
|
19
20
|
## Middlewares
|
|
20
21
|
|
|
@@ -158,7 +159,7 @@ export default withKoaRouter(router);
|
|
|
158
159
|
[2]: https://nextjs.org/
|
|
159
160
|
[3]: https://libraries.io/npm/next-ssr-middleware
|
|
160
161
|
[4]: https://github.com/idea2app/Next-SSR-middleware/actions/workflows/main.yml
|
|
161
|
-
[5]: https://
|
|
162
|
+
[5]: https://npm.im/next-ssr-middleware/
|
|
162
163
|
[6]: https://github.com/idea2app/MobX-i18n
|
|
163
164
|
[7]: https://github.com/idea2app/MobX-i18n#server-side-rendering-nextjs-example
|
|
164
165
|
[8]: https://github.com/idea2app/Lark-Next-Bootstrap-ts/tree/main/pages/api
|
package/dist/API.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Router,
|
|
1
|
+
import { Router, RouterOptions, RouterContext, RouterInstance } from '@koa/router';
|
|
2
2
|
import Koa, { Middleware } from 'koa';
|
|
3
3
|
export type KoaOption = ConstructorParameters<typeof Koa>[0];
|
|
4
4
|
export type KoaCallback = ReturnType<(typeof Koa)['prototype']['callback']>;
|
|
5
5
|
export declare function withKoa<S, C>(...middlewares: Middleware<S, C>[]): KoaCallback;
|
|
6
6
|
export declare function withKoa<S, C>(option: KoaOption, ...middlewares: Middleware<S, C>[]): KoaCallback;
|
|
7
7
|
export declare const pageApiRouteOf: (path: string) => string;
|
|
8
|
-
export declare const createKoaRouter: <S, C extends
|
|
9
|
-
export declare function withKoaRouter<S, C extends
|
|
10
|
-
export declare function withKoaRouter<S, C extends
|
|
8
|
+
export declare const createKoaRouter: <S, C extends RouterContext<S>>(moduleURI: string, option?: RouterOptions) => Router<S, C>;
|
|
9
|
+
export declare function withKoaRouter<S, C extends RouterContext<S>>(router: RouterInstance<S, C>, ...middlewares: Middleware<S, C>[]): KoaCallback;
|
|
10
|
+
export declare function withKoaRouter<S, C extends RouterContext<S>>(option: KoaOption, router: RouterInstance<S, C>, ...middlewares: Middleware<S, C>[]): KoaCallback;
|
package/dist/API.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.withKoa = withKoa;
|
|
|
5
5
|
exports.withKoaRouter = withKoaRouter;
|
|
6
6
|
var tslib_1 = require("tslib");
|
|
7
7
|
var bodyparser_1 = tslib_1.__importDefault(require("@koa/bodyparser"));
|
|
8
|
-
var router_1 =
|
|
8
|
+
var router_1 = require("@koa/router");
|
|
9
9
|
var koa_1 = tslib_1.__importDefault(require("koa"));
|
|
10
10
|
function withKoa() {
|
|
11
11
|
var _a, e_1, _b;
|
|
@@ -43,7 +43,7 @@ var pageApiRouteOf = function (path) {
|
|
|
43
43
|
.match(/pages(\/api\/.+)\.(j|t)s/)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split('/[')[0]) === null || _c === void 0 ? void 0 : _c.replace(/\/index$/, '');
|
|
44
44
|
};
|
|
45
45
|
exports.pageApiRouteOf = pageApiRouteOf;
|
|
46
|
-
var createKoaRouter = function (moduleURI, option) { return new router_1.
|
|
46
|
+
var createKoaRouter = function (moduleURI, option) { return new router_1.Router(tslib_1.__assign(tslib_1.__assign({}, option), { prefix: (0, exports.pageApiRouteOf)(moduleURI) })); };
|
|
47
47
|
exports.createKoaRouter = createKoaRouter;
|
|
48
48
|
function withKoaRouter() {
|
|
49
49
|
var _a, _b;
|
package/dist/API.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"API.js","sourceRoot":"","sources":["../source/API.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"API.js","sourceRoot":"","sources":["../source/API.ts"],"names":[],"mappings":";;;AAkBA,0BAcC;AAsBD,sCAiBC;;AAvED,uEAAyC;AACzC,sCAKqB;AACrB,oDAAsC;AAWtC,SAAgB,OAAO;;IAAO,oBAAoB;SAApB,UAAoB,EAApB,qBAAoB,EAApB,IAAoB;QAApB,+BAAoB;;IAC9C,IAAI,MAA6B,CAAC;IAClC,IAAI,WAAW,GAAuB,EAAE,CAAC;IAEzC,IAAI,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;QACtC,MAAM,GAAG,SAAS,CAAC;QACnB,WAAW,GAAG,UAAU,CAAC;IAC7B,CAAC;;QAAM,KAAA,eAA2B,UAAU,CAAA,EAApC,MAAM,QAAA,EAAK,WAAW,cAAA,CAAe;IAE7C,IAAM,GAAG,GAAG,IAAI,aAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAA,oBAAU,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AChB;AACN,CAAC"}
|
package/dist/SSR/shim.js
CHANGED
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withMiddleware = void 0;
|
|
4
4
|
exports.patchHeaders = patchHeaders;
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
|
-
var headers_1 = require("next/headers");
|
|
7
|
-
var navigation_1 = require("next/navigation");
|
|
8
6
|
/**
|
|
9
7
|
* @see {@link https://www.propelauth.com/post/getting-url-in-next-server-components}
|
|
10
8
|
*/
|
|
@@ -20,27 +18,30 @@ function patchHeaders(request) {
|
|
|
20
18
|
}
|
|
21
19
|
var withMiddleware = function (getServerSideProps, serverComponent) {
|
|
22
20
|
return function (_a) { return tslib_1.__awaiter(void 0, [_a], void 0, function (_b) {
|
|
23
|
-
var resolvedParams, resolvedSearchParams, header, cookie, isEnabled, url, locale, locales, defaultLocale, req, context, result, isPermanent, destination, props;
|
|
24
|
-
var
|
|
21
|
+
var _c, headers, cookies, draftMode, resolvedParams, resolvedSearchParams, header, cookie, isEnabled, url, locale, locales, defaultLocale, req, context, result, _d, redirect, permanentRedirect, isPermanent, destination, props;
|
|
22
|
+
var _e;
|
|
25
23
|
var params = _b.params, searchParams = _b.searchParams;
|
|
26
|
-
return tslib_1.__generator(this, function (
|
|
27
|
-
switch (
|
|
28
|
-
case 0: return [4 /*yield*/,
|
|
24
|
+
return tslib_1.__generator(this, function (_f) {
|
|
25
|
+
switch (_f.label) {
|
|
26
|
+
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('next/headers')); })];
|
|
29
27
|
case 1:
|
|
30
|
-
|
|
31
|
-
return [4 /*yield*/,
|
|
28
|
+
_c = _f.sent(), headers = _c.headers, cookies = _c.cookies, draftMode = _c.draftMode;
|
|
29
|
+
return [4 /*yield*/, params];
|
|
32
30
|
case 2:
|
|
33
|
-
|
|
34
|
-
return [4 /*yield*/,
|
|
31
|
+
resolvedParams = _f.sent();
|
|
32
|
+
return [4 /*yield*/, searchParams];
|
|
35
33
|
case 3:
|
|
36
|
-
|
|
37
|
-
return [4 /*yield*/, (
|
|
34
|
+
resolvedSearchParams = _f.sent();
|
|
35
|
+
return [4 /*yield*/, headers()];
|
|
38
36
|
case 4:
|
|
39
|
-
|
|
40
|
-
return [4 /*yield*/, (
|
|
37
|
+
header = _f.sent();
|
|
38
|
+
return [4 /*yield*/, cookies()];
|
|
41
39
|
case 5:
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
cookie = _f.sent();
|
|
41
|
+
return [4 /*yield*/, draftMode()];
|
|
42
|
+
case 6:
|
|
43
|
+
isEnabled = (_f.sent()).isEnabled;
|
|
44
|
+
url = header.get('x-resolved-url') || '', locale = header.get('x-locale') || '', locales = ((_e = header.get('x-locales')) === null || _e === void 0 ? void 0 : _e.split(',')) || [], defaultLocale = header.get('x-default-locale') || '';
|
|
44
45
|
req = {
|
|
45
46
|
url: url,
|
|
46
47
|
headers: Object.fromEntries(tslib_1.__spreadArray([], tslib_1.__read(header), false)),
|
|
@@ -63,25 +64,29 @@ var withMiddleware = function (getServerSideProps, serverComponent) {
|
|
|
63
64
|
defaultLocale: defaultLocale
|
|
64
65
|
};
|
|
65
66
|
return [4 /*yield*/, getServerSideProps(context)];
|
|
66
|
-
case 6:
|
|
67
|
-
result = _d.sent();
|
|
68
|
-
if ('redirect' in result) {
|
|
69
|
-
isPermanent = 'statusCode' in result.redirect
|
|
70
|
-
? result.redirect.statusCode === 308
|
|
71
|
-
: 'permanent' in result.redirect &&
|
|
72
|
-
result.redirect.permanent;
|
|
73
|
-
destination = result.redirect.destination;
|
|
74
|
-
if (isPermanent)
|
|
75
|
-
(0, navigation_1.permanentRedirect)(destination);
|
|
76
|
-
else
|
|
77
|
-
(0, navigation_1.redirect)(destination);
|
|
78
|
-
}
|
|
79
|
-
if (!('props' in result)) return [3 /*break*/, 8];
|
|
80
|
-
return [4 /*yield*/, result.props];
|
|
81
67
|
case 7:
|
|
82
|
-
|
|
68
|
+
result = _f.sent();
|
|
69
|
+
if (!('redirect' in result)) return [3 /*break*/, 9];
|
|
70
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('next/navigation')); })];
|
|
71
|
+
case 8:
|
|
72
|
+
_d = _f.sent(), redirect = _d.redirect, permanentRedirect = _d.permanentRedirect;
|
|
73
|
+
isPermanent = 'statusCode' in result.redirect
|
|
74
|
+
? result.redirect.statusCode === 308
|
|
75
|
+
: 'permanent' in result.redirect &&
|
|
76
|
+
result.redirect.permanent;
|
|
77
|
+
destination = result.redirect.destination;
|
|
78
|
+
if (isPermanent)
|
|
79
|
+
permanentRedirect(destination);
|
|
80
|
+
else
|
|
81
|
+
redirect(destination);
|
|
82
|
+
_f.label = 9;
|
|
83
|
+
case 9:
|
|
84
|
+
if (!('props' in result)) return [3 /*break*/, 11];
|
|
85
|
+
return [4 /*yield*/, result.props];
|
|
86
|
+
case 10:
|
|
87
|
+
props = _f.sent();
|
|
83
88
|
return [2 /*return*/, serverComponent(tslib_1.__assign({ params: params, searchParams: searchParams }, props))];
|
|
84
|
-
case
|
|
89
|
+
case 11: return [2 /*return*/];
|
|
85
90
|
}
|
|
86
91
|
});
|
|
87
92
|
}); };
|
package/dist/SSR/shim.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shim.js","sourceRoot":"","sources":["../../source/SSR/shim.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"shim.js","sourceRoot":"","sources":["../../source/SSR/shim.ts"],"names":[],"mappings":";;;AAcA,oCAYC;;AAfD;;GAEG;AACH,SAAgB,YAAY,CAAC,OAAoB;;IAC7C,IAAM,WAAW,GAAG,OAAO,CAAC,OAAO,GAAG,EAAE,EACpC,KAA+C,OAAO,CAAC,OAAO,EAA5D,MAAM,YAAA,EAAE,qBAAkB,EAAlB,aAAa,mBAAG,EAAE,KAAA,EAAE,YAAY,kBAAA,EAC1C,OAAO,GAAG,IAAI,OAAO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BAC3C,QAAQ,CAAC,WAAW,CAAC,CAAC;;;yBAE3B,CAAA,OAAO,IAAI,MAAM,CAAA,EAAjB,yBAAiB;oBACH,qBAAM,MAAM,CAAC,KAAK,EAAA;;oBAA1B,KAAK,GAAG,SAAkB;oBAEhC,sBAAO,eAAe,oBAAG,MAAM,QAAA,EAAE,YAAY,cAAA,IAAK,KAAK,EAAG,EAAC;;;;SAElE;AAvDD,CAuDC,CAAC;AA5DO,QAAA,cAAc,kBA4DrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-ssr-middleware",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
5
|
"author": "shiy2008@gmail.com",
|
|
6
6
|
"description": "Koa-like middlewares for Next.js Back-end API & Server Side Rendering",
|
|
@@ -22,31 +22,30 @@
|
|
|
22
22
|
"types": "dist/index.d.ts",
|
|
23
23
|
"main": "dist/index.js",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@koa/bodyparser": "
|
|
26
|
-
"@koa/router": "
|
|
25
|
+
"@koa/bodyparser": "^6.1.0",
|
|
26
|
+
"@koa/router": "^15.7.0",
|
|
27
27
|
"@types/jsonwebtoken": "^9.0.10",
|
|
28
|
-
"@types/koa": "
|
|
29
|
-
"@types/
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"koa": ">=2",
|
|
28
|
+
"@types/koa": "^3.0.3",
|
|
29
|
+
"@types/react": "^19.2.17",
|
|
30
|
+
"jsonwebtoken": "^9.0.3",
|
|
31
|
+
"koa": "^3.2.1",
|
|
33
32
|
"tslib": "^2.8.1",
|
|
34
|
-
"web-utility": "^4.
|
|
33
|
+
"web-utility": "^4.7.2"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
37
|
-
"next": ">=
|
|
36
|
+
"next": ">=15.5.18",
|
|
38
37
|
"react": ">=18"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.13.3",
|
|
42
41
|
"husky": "^9.1.7",
|
|
43
|
-
"koajax": "^3.
|
|
44
|
-
"lint-staged": "^
|
|
45
|
-
"next": "^
|
|
46
|
-
"open-cli": "^
|
|
47
|
-
"prettier": "^3.
|
|
48
|
-
"typedoc": "^0.28.
|
|
49
|
-
"typescript": "~5.9.
|
|
42
|
+
"koajax": "^3.3.0",
|
|
43
|
+
"lint-staged": "^17.0.8",
|
|
44
|
+
"next": "^16.2.10",
|
|
45
|
+
"open-cli": "^9.0.0",
|
|
46
|
+
"prettier": "^3.9.5",
|
|
47
|
+
"typedoc": "^0.28.20",
|
|
48
|
+
"typescript": "~5.9.3"
|
|
50
49
|
},
|
|
51
50
|
"pnpm": {
|
|
52
51
|
"onlyBuiltDependencies": [
|
package/source/API.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import BodyParser from '@koa/bodyparser';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
Router,
|
|
4
|
+
RouterOptions,
|
|
5
|
+
RouterContext,
|
|
6
|
+
RouterInstance
|
|
7
|
+
} from '@koa/router';
|
|
3
8
|
import Koa, { Middleware } from 'koa';
|
|
4
9
|
|
|
5
10
|
export type KoaOption = ConstructorParameters<typeof Koa>[0];
|
|
@@ -33,25 +38,25 @@ export const pageApiRouteOf = (path: string) =>
|
|
|
33
38
|
?.split('/[')[0]
|
|
34
39
|
?.replace(/\/index$/, '');
|
|
35
40
|
|
|
36
|
-
export const createKoaRouter = <S, C extends
|
|
41
|
+
export const createKoaRouter = <S, C extends RouterContext<S>>(
|
|
37
42
|
moduleURI: string,
|
|
38
43
|
option?: RouterOptions
|
|
39
44
|
) => new Router<S, C>({ ...option, prefix: pageApiRouteOf(moduleURI) });
|
|
40
45
|
|
|
41
|
-
export function withKoaRouter<S, C extends
|
|
42
|
-
router:
|
|
46
|
+
export function withKoaRouter<S, C extends RouterContext<S>>(
|
|
47
|
+
router: RouterInstance<S, C>,
|
|
43
48
|
...middlewares: Middleware<S, C>[]
|
|
44
49
|
): KoaCallback;
|
|
45
|
-
export function withKoaRouter<S, C extends
|
|
50
|
+
export function withKoaRouter<S, C extends RouterContext<S>>(
|
|
46
51
|
option: KoaOption,
|
|
47
|
-
router:
|
|
52
|
+
router: RouterInstance<S, C>,
|
|
48
53
|
...middlewares: Middleware<S, C>[]
|
|
49
54
|
): KoaCallback;
|
|
50
|
-
export function withKoaRouter<S, C extends
|
|
55
|
+
export function withKoaRouter<S, C extends RouterContext<S>>(
|
|
51
56
|
...parameters: any[]
|
|
52
57
|
) {
|
|
53
58
|
let option: KoaOption | undefined;
|
|
54
|
-
let router:
|
|
59
|
+
let router: RouterInstance<S, C>;
|
|
55
60
|
let middlewares: Middleware<S, C>[] = [];
|
|
56
61
|
|
|
57
62
|
if (!parameters[1] || typeof parameters[1] === 'function')
|
package/source/SSR/shim.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
2
|
import { NextApiRequestCookies } from 'next/dist/server/api-utils';
|
|
3
|
-
import { cookies, draftMode, headers } from 'next/headers';
|
|
4
|
-
import { permanentRedirect, redirect } from 'next/navigation';
|
|
5
3
|
import { NextRequest } from 'next/server';
|
|
6
4
|
import {
|
|
7
5
|
GetServerSideProps,
|
|
@@ -47,6 +45,8 @@ export const withMiddleware =
|
|
|
47
45
|
serverComponent: ServerComponent<I, O>
|
|
48
46
|
): ServerComponent<I> =>
|
|
49
47
|
async ({ params, searchParams }) => {
|
|
48
|
+
const { headers, cookies, draftMode } = await import('next/headers');
|
|
49
|
+
|
|
50
50
|
const resolvedParams = await params,
|
|
51
51
|
resolvedSearchParams = await searchParams,
|
|
52
52
|
header = await headers(),
|
|
@@ -81,6 +81,9 @@ export const withMiddleware =
|
|
|
81
81
|
const result = await getServerSideProps(context);
|
|
82
82
|
|
|
83
83
|
if ('redirect' in result) {
|
|
84
|
+
const { redirect, permanentRedirect } =
|
|
85
|
+
await import('next/navigation');
|
|
86
|
+
|
|
84
87
|
const isPermanent =
|
|
85
88
|
'statusCode' in result.redirect
|
|
86
89
|
? result.redirect.statusCode === 308
|