@modern-js/plugin-koa 2.27.0 → 2.28.0
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/CHANGELOG.md +11 -0
- package/dist/cjs/plugin.js +88 -92
- package/dist/esm/plugin.js +2 -2
- package/dist/esm-node/plugin.js +88 -92
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @modern-js/plugin-koa
|
|
2
2
|
|
|
3
|
+
## 2.28.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4e3ce96]
|
|
8
|
+
- Updated dependencies [00b58a7]
|
|
9
|
+
- @modern-js/types@2.28.0
|
|
10
|
+
- @modern-js/utils@2.28.0
|
|
11
|
+
- @modern-js/bff-core@2.28.0
|
|
12
|
+
- @modern-js/bff-runtime@2.28.0
|
|
13
|
+
|
|
3
14
|
## 2.27.0
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -37,100 +37,96 @@ const initMiddlewares = (middleware, app) => {
|
|
|
37
37
|
app.use(middlewareFunc);
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
-
const _default = () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (html) {
|
|
93
|
-
ctx.body = html;
|
|
94
|
-
}
|
|
95
|
-
await next();
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return (req, res) => {
|
|
99
|
-
return Promise.resolve(app.callback()(req, res));
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
prepareWebServer({ config }, next) {
|
|
103
|
-
var _userConfig_server;
|
|
104
|
-
const userConfig = api.useConfigContext();
|
|
105
|
-
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
106
|
-
return next();
|
|
40
|
+
const _default = () => ({
|
|
41
|
+
name: "@modern-js/plugin-koa",
|
|
42
|
+
pre: [
|
|
43
|
+
"@modern-js/plugin-bff"
|
|
44
|
+
],
|
|
45
|
+
post: [
|
|
46
|
+
"@modern-js/plugin-server"
|
|
47
|
+
],
|
|
48
|
+
setup: (api) => ({
|
|
49
|
+
async prepareApiServer({ pwd, config, render }) {
|
|
50
|
+
var _userConfig_bff;
|
|
51
|
+
let app;
|
|
52
|
+
const router = new _koarouter.default();
|
|
53
|
+
const apiDir = _path.join(pwd, "./api");
|
|
54
|
+
const appContext = api.useAppContext();
|
|
55
|
+
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
56
|
+
const mode = appContext.apiMode;
|
|
57
|
+
const userConfig = api.useConfigContext();
|
|
58
|
+
if (mode === "framework") {
|
|
59
|
+
app = await findAppModule(apiDir);
|
|
60
|
+
if (!(app instanceof _koa.default)) {
|
|
61
|
+
app = new _koa.default();
|
|
62
|
+
app.use((0, _koabody.default)({
|
|
63
|
+
multipart: true
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
if (config) {
|
|
67
|
+
const { middleware } = config;
|
|
68
|
+
initMiddlewares(middleware, app);
|
|
69
|
+
}
|
|
70
|
+
app.use(_context.run);
|
|
71
|
+
(0, _registerRoutes.default)(router, apiHandlerInfos);
|
|
72
|
+
} else if (mode === "function") {
|
|
73
|
+
app = new _koa.default();
|
|
74
|
+
app.use((0, _koabody.default)({
|
|
75
|
+
multipart: true
|
|
76
|
+
}));
|
|
77
|
+
if (config) {
|
|
78
|
+
const { middleware } = config;
|
|
79
|
+
initMiddlewares(middleware, app);
|
|
80
|
+
}
|
|
81
|
+
app.use(_context.run);
|
|
82
|
+
(0, _registerRoutes.default)(router, apiHandlerInfos);
|
|
83
|
+
} else {
|
|
84
|
+
throw new Error(`mode must be function or framework`);
|
|
85
|
+
}
|
|
86
|
+
app.use(router.routes());
|
|
87
|
+
if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
|
|
88
|
+
app.use(async (ctx, next) => {
|
|
89
|
+
const html = await render(ctx.req, ctx.res);
|
|
90
|
+
if (html) {
|
|
91
|
+
ctx.body = html;
|
|
107
92
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
93
|
+
await next();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return (req, res) => {
|
|
97
|
+
return Promise.resolve(app.callback()(req, res));
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
prepareWebServer({ config }, next) {
|
|
101
|
+
var _userConfig_server, _userConfig;
|
|
102
|
+
const userConfig = api.useConfigContext();
|
|
103
|
+
if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
104
|
+
return next();
|
|
105
|
+
}
|
|
106
|
+
const app = new _koa.default();
|
|
107
|
+
app.use(async (ctx, next2) => {
|
|
108
|
+
await next2();
|
|
109
|
+
if (!ctx.body) {
|
|
110
|
+
if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
|
|
111
|
+
ctx.res.statusCode = 200;
|
|
122
112
|
}
|
|
123
|
-
|
|
124
|
-
const { source: { req, res } } = ctx;
|
|
125
|
-
app.on("error", (err) => {
|
|
126
|
-
if (err) {
|
|
127
|
-
throw err;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
return Promise.resolve(app.callback()(req, res));
|
|
131
|
-
};
|
|
113
|
+
ctx.respond = false;
|
|
132
114
|
}
|
|
115
|
+
});
|
|
116
|
+
app.use((0, _koabody.default)());
|
|
117
|
+
if (config) {
|
|
118
|
+
const { middleware } = config;
|
|
119
|
+
initMiddlewares(middleware, app);
|
|
120
|
+
}
|
|
121
|
+
return (ctx) => {
|
|
122
|
+
const { source: { req, res } } = ctx;
|
|
123
|
+
app.on("error", (err) => {
|
|
124
|
+
if (err) {
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return Promise.resolve(app.callback()(req, res));
|
|
133
129
|
};
|
|
134
130
|
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
131
|
+
})
|
|
132
|
+
});
|
package/dist/esm/plugin.js
CHANGED
|
@@ -216,9 +216,9 @@ export default function() {
|
|
|
216
216
|
},
|
|
217
217
|
prepareWebServer: function prepareWebServer(param, next) {
|
|
218
218
|
var config = param.config;
|
|
219
|
-
var _userConfig_server;
|
|
219
|
+
var _userConfig_server, _userConfig;
|
|
220
220
|
var userConfig = api.useConfigContext();
|
|
221
|
-
if (!(userConfig === null ||
|
|
221
|
+
if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
222
222
|
return next();
|
|
223
223
|
}
|
|
224
224
|
var app = new Koa();
|
package/dist/esm-node/plugin.js
CHANGED
|
@@ -25,100 +25,96 @@ const initMiddlewares = (middleware, app) => {
|
|
|
25
25
|
app.use(middlewareFunc);
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
-
export default () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (html) {
|
|
81
|
-
ctx.body = html;
|
|
82
|
-
}
|
|
83
|
-
await next();
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return (req, res) => {
|
|
87
|
-
return Promise.resolve(app.callback()(req, res));
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
prepareWebServer({ config }, next) {
|
|
91
|
-
var _userConfig_server;
|
|
92
|
-
const userConfig = api.useConfigContext();
|
|
93
|
-
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
94
|
-
return next();
|
|
28
|
+
export default () => ({
|
|
29
|
+
name: "@modern-js/plugin-koa",
|
|
30
|
+
pre: [
|
|
31
|
+
"@modern-js/plugin-bff"
|
|
32
|
+
],
|
|
33
|
+
post: [
|
|
34
|
+
"@modern-js/plugin-server"
|
|
35
|
+
],
|
|
36
|
+
setup: (api) => ({
|
|
37
|
+
async prepareApiServer({ pwd, config, render }) {
|
|
38
|
+
var _userConfig_bff;
|
|
39
|
+
let app;
|
|
40
|
+
const router = new Router();
|
|
41
|
+
const apiDir = path.join(pwd, "./api");
|
|
42
|
+
const appContext = api.useAppContext();
|
|
43
|
+
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
44
|
+
const mode = appContext.apiMode;
|
|
45
|
+
const userConfig = api.useConfigContext();
|
|
46
|
+
if (mode === "framework") {
|
|
47
|
+
app = await findAppModule(apiDir);
|
|
48
|
+
if (!(app instanceof Koa)) {
|
|
49
|
+
app = new Koa();
|
|
50
|
+
app.use(koaBody({
|
|
51
|
+
multipart: true
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
if (config) {
|
|
55
|
+
const { middleware } = config;
|
|
56
|
+
initMiddlewares(middleware, app);
|
|
57
|
+
}
|
|
58
|
+
app.use(run);
|
|
59
|
+
registerRoutes(router, apiHandlerInfos);
|
|
60
|
+
} else if (mode === "function") {
|
|
61
|
+
app = new Koa();
|
|
62
|
+
app.use(koaBody({
|
|
63
|
+
multipart: true
|
|
64
|
+
}));
|
|
65
|
+
if (config) {
|
|
66
|
+
const { middleware } = config;
|
|
67
|
+
initMiddlewares(middleware, app);
|
|
68
|
+
}
|
|
69
|
+
app.use(run);
|
|
70
|
+
registerRoutes(router, apiHandlerInfos);
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error(`mode must be function or framework`);
|
|
73
|
+
}
|
|
74
|
+
app.use(router.routes());
|
|
75
|
+
if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
|
|
76
|
+
app.use(async (ctx, next) => {
|
|
77
|
+
const html = await render(ctx.req, ctx.res);
|
|
78
|
+
if (html) {
|
|
79
|
+
ctx.body = html;
|
|
95
80
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
81
|
+
await next();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return (req, res) => {
|
|
85
|
+
return Promise.resolve(app.callback()(req, res));
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
prepareWebServer({ config }, next) {
|
|
89
|
+
var _userConfig_server, _userConfig;
|
|
90
|
+
const userConfig = api.useConfigContext();
|
|
91
|
+
if (!((_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_server = _userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
92
|
+
return next();
|
|
93
|
+
}
|
|
94
|
+
const app = new Koa();
|
|
95
|
+
app.use(async (ctx, next2) => {
|
|
96
|
+
await next2();
|
|
97
|
+
if (!ctx.body) {
|
|
98
|
+
if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
|
|
99
|
+
ctx.res.statusCode = 200;
|
|
110
100
|
}
|
|
111
|
-
|
|
112
|
-
const { source: { req, res } } = ctx;
|
|
113
|
-
app.on("error", (err) => {
|
|
114
|
-
if (err) {
|
|
115
|
-
throw err;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return Promise.resolve(app.callback()(req, res));
|
|
119
|
-
};
|
|
101
|
+
ctx.respond = false;
|
|
120
102
|
}
|
|
103
|
+
});
|
|
104
|
+
app.use(koaBody());
|
|
105
|
+
if (config) {
|
|
106
|
+
const { middleware } = config;
|
|
107
|
+
initMiddlewares(middleware, app);
|
|
108
|
+
}
|
|
109
|
+
return (ctx) => {
|
|
110
|
+
const { source: { req, res } } = ctx;
|
|
111
|
+
app.on("error", (err) => {
|
|
112
|
+
if (err) {
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return Promise.resolve(app.callback()(req, res));
|
|
121
117
|
};
|
|
122
118
|
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
119
|
+
})
|
|
120
|
+
});
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.28.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/cli/index.js",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"koa-router": "^10.0.0",
|
|
68
68
|
"type-is": "^1.6.18",
|
|
69
69
|
"@swc/helpers": "0.5.1",
|
|
70
|
-
"@modern-js/bff-core": "2.
|
|
71
|
-
"@modern-js/bff-runtime": "2.
|
|
72
|
-
"@modern-js/utils": "2.
|
|
73
|
-
"@modern-js/types": "2.
|
|
70
|
+
"@modern-js/bff-core": "2.28.0",
|
|
71
|
+
"@modern-js/bff-runtime": "2.28.0",
|
|
72
|
+
"@modern-js/utils": "2.28.0",
|
|
73
|
+
"@modern-js/types": "2.28.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/jest": "^29",
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"supertest": "^6.1.6",
|
|
85
85
|
"typescript": "^5",
|
|
86
86
|
"zod": "^3.17.3",
|
|
87
|
-
"@modern-js/core": "2.
|
|
88
|
-
"@modern-js/server-core": "2.
|
|
89
|
-
"@modern-js/app-tools": "2.
|
|
90
|
-
"@scripts/
|
|
91
|
-
"@scripts/
|
|
87
|
+
"@modern-js/core": "2.28.0",
|
|
88
|
+
"@modern-js/server-core": "2.28.0",
|
|
89
|
+
"@modern-js/app-tools": "2.28.0",
|
|
90
|
+
"@scripts/jest-config": "2.28.0",
|
|
91
|
+
"@scripts/build": "2.28.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"koa": "^2.13.3"
|