@modern-js/plugin-koa 2.14.0 → 2.16.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 +25 -0
- package/dist/cjs/cli/index.js +57 -50
- package/dist/cjs/context.js +13 -26
- package/dist/cjs/index.js +28 -37
- package/dist/cjs/plugin.js +158 -134
- package/dist/cjs/registerRoutes.js +10 -26
- package/dist/cjs/runtime.js +27 -28
- package/dist/cjs/utils.js +36 -54
- package/dist/esm/cli/index.js +47 -47
- package/dist/esm/index.js +1 -2
- package/dist/esm/plugin.js +374 -365
- package/dist/esm/registerRoutes.js +7 -8
- package/dist/esm/runtime.js +3 -4
- package/dist/esm/utils.js +391 -369
- package/dist/esm-node/cli/index.js +7 -17
- package/dist/esm-node/context.js +1 -4
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/plugin.js +94 -92
- package/dist/esm-node/registerRoutes.js +1 -4
- package/dist/esm-node/runtime.js +2 -6
- package/dist/esm-node/utils.js +14 -23
- package/package.json +15 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @modern-js/plugin-koa
|
|
2
2
|
|
|
3
|
+
## 2.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
8
|
+
|
|
9
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5954330]
|
|
12
|
+
- Updated dependencies [7596520]
|
|
13
|
+
- Updated dependencies [4e876ab]
|
|
14
|
+
- @modern-js/utils@2.16.0
|
|
15
|
+
- @modern-js/bff-runtime@2.16.0
|
|
16
|
+
- @modern-js/bff-core@2.16.0
|
|
17
|
+
- @modern-js/types@2.16.0
|
|
18
|
+
|
|
19
|
+
## 2.15.0
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- @modern-js/bff-core@2.15.0
|
|
24
|
+
- @modern-js/bff-runtime@2.15.0
|
|
25
|
+
- @modern-js/types@2.15.0
|
|
26
|
+
- @modern-js/utils@2.15.0
|
|
27
|
+
|
|
3
28
|
## 2.14.0
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -1,50 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var cli_exports = {};
|
|
29
|
-
__export(cli_exports, {
|
|
30
|
-
default: () => cli_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
31
8
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
10
|
+
const _utils = require("@modern-js/utils");
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
12
|
+
if (typeof WeakMap !== "function")
|
|
13
|
+
return null;
|
|
14
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
17
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
18
|
+
})(nodeInterop);
|
|
19
|
+
}
|
|
20
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
21
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
25
|
+
return {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
30
|
+
if (cache && cache.has(obj)) {
|
|
31
|
+
return cache.get(obj);
|
|
32
|
+
}
|
|
33
|
+
var newObj = {};
|
|
34
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
35
|
+
for (var key in obj) {
|
|
36
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
37
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
38
|
+
if (desc && (desc.get || desc.set)) {
|
|
39
|
+
Object.defineProperty(newObj, key, desc);
|
|
40
|
+
} else {
|
|
41
|
+
newObj[key] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
newObj.default = obj;
|
|
46
|
+
if (cache) {
|
|
47
|
+
cache.set(obj, newObj);
|
|
48
|
+
}
|
|
49
|
+
return newObj;
|
|
50
|
+
}
|
|
51
|
+
const _default = () => ({
|
|
36
52
|
name: "@modern-js/plugin-koa",
|
|
37
53
|
setup: (api) => {
|
|
38
54
|
let bffExportsUtils;
|
|
39
55
|
const { useAppContext } = api;
|
|
40
|
-
const runtimeModulePath =
|
|
56
|
+
const runtimeModulePath = _path.resolve(__dirname, "../runtime");
|
|
41
57
|
return {
|
|
42
58
|
config() {
|
|
43
59
|
const appContext = useAppContext();
|
|
44
|
-
bffExportsUtils = (0,
|
|
45
|
-
appContext.internalDirectory,
|
|
46
|
-
"server"
|
|
47
|
-
);
|
|
60
|
+
bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "server");
|
|
48
61
|
const runtimePath = "@modern-js/plugin-koa/runtime";
|
|
49
62
|
const alias = process.env.NODE_ENV === "production" ? runtimePath : require.resolve(runtimePath);
|
|
50
63
|
return {
|
|
@@ -65,18 +78,14 @@ var cli_default = () => ({
|
|
|
65
78
|
plugins.push({
|
|
66
79
|
"@modern-js/plugin-koa": "@modern-js/plugin-koa/server"
|
|
67
80
|
});
|
|
68
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
plugins
|
|
83
|
+
};
|
|
69
84
|
},
|
|
70
85
|
addRuntimeExports(input) {
|
|
71
86
|
const currentFile = bffExportsUtils.getPath();
|
|
72
|
-
const relativeRuntimeModulePath =
|
|
73
|
-
|
|
74
|
-
runtimeModulePath
|
|
75
|
-
);
|
|
76
|
-
const relativeFramePath = path.relative(
|
|
77
|
-
path.dirname(currentFile),
|
|
78
|
-
require.resolve("koa")
|
|
79
|
-
);
|
|
87
|
+
const relativeRuntimeModulePath = _path.relative(_path.dirname(currentFile), runtimeModulePath);
|
|
88
|
+
const relativeFramePath = _path.relative(_path.dirname(currentFile), require.resolve("koa"));
|
|
80
89
|
bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
|
|
81
90
|
const Koa = require('${relativeFramePath}')
|
|
82
91
|
module.exports = {
|
|
@@ -89,5 +98,3 @@ var cli_default = () => ({
|
|
|
89
98
|
};
|
|
90
99
|
}
|
|
91
100
|
});
|
|
92
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
-
0 && (module.exports = {});
|
package/dist/cjs/context.js
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var context_exports = {};
|
|
19
|
-
__export(context_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
run: () => run,
|
|
21
14
|
useContext: () => useContext
|
|
22
15
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const { run, useContext } = (0, import_bff_core.createStorage)();
|
|
26
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
-
0 && (module.exports = {
|
|
28
|
-
run,
|
|
29
|
-
useContext
|
|
30
|
-
});
|
|
16
|
+
const _bffcore = require("@modern-js/bff-core");
|
|
17
|
+
const { run, useContext } = (0, _bffcore.createStorage)();
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var src_exports = {};
|
|
30
|
-
__export(src_exports, {
|
|
31
|
-
default: () => src_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
32
4
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
8
|
+
});
|
|
9
|
+
const _plugin = /* @__PURE__ */ _interop_require_default(require("./plugin"));
|
|
10
|
+
_export_star(require("./context"), exports);
|
|
11
|
+
function _export_star(from, to) {
|
|
12
|
+
Object.keys(from).forEach(function(k) {
|
|
13
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
14
|
+
Object.defineProperty(to, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return from[k];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return from;
|
|
23
|
+
}
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const _default = _plugin.default;
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -1,153 +1,177 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var plugin_exports = {};
|
|
29
|
-
__export(plugin_exports, {
|
|
30
|
-
default: () => plugin_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
31
8
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
10
|
+
const _koa = /* @__PURE__ */ _interop_require_default(require("koa"));
|
|
11
|
+
const _koarouter = /* @__PURE__ */ _interop_require_default(require("koa-router"));
|
|
12
|
+
const _koabody = /* @__PURE__ */ _interop_require_default(require("koa-body"));
|
|
13
|
+
const _utils = require("@modern-js/utils");
|
|
14
|
+
const _context = require("./context");
|
|
15
|
+
const _registerRoutes = /* @__PURE__ */ _interop_require_default(require("./registerRoutes"));
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
+
if (typeof WeakMap !== "function")
|
|
23
|
+
return null;
|
|
24
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
25
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
27
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
28
|
+
})(nodeInterop);
|
|
29
|
+
}
|
|
30
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
31
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
35
|
+
return {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
40
|
+
if (cache && cache.has(obj)) {
|
|
41
|
+
return cache.get(obj);
|
|
42
|
+
}
|
|
43
|
+
var newObj = {};
|
|
44
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
|
+
for (var key in obj) {
|
|
46
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
47
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
48
|
+
if (desc && (desc.get || desc.set)) {
|
|
49
|
+
Object.defineProperty(newObj, key, desc);
|
|
50
|
+
} else {
|
|
51
|
+
newObj[key] = obj[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
newObj.default = obj;
|
|
56
|
+
if (cache) {
|
|
57
|
+
cache.set(obj, newObj);
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
40
61
|
const findAppModule = async (apiDir) => {
|
|
41
|
-
const exts = [
|
|
42
|
-
|
|
62
|
+
const exts = [
|
|
63
|
+
".ts",
|
|
64
|
+
".js"
|
|
65
|
+
];
|
|
66
|
+
const paths = exts.map((ext) => _path.join(apiDir, `app${ext}`));
|
|
43
67
|
for (const filename of paths) {
|
|
44
|
-
if (await
|
|
68
|
+
if (await _utils.fs.pathExists(filename)) {
|
|
45
69
|
delete require.cache[filename];
|
|
46
|
-
return (0,
|
|
70
|
+
return (0, _utils.compatRequire)(filename);
|
|
47
71
|
}
|
|
48
72
|
}
|
|
49
73
|
return null;
|
|
50
74
|
};
|
|
51
75
|
const initMiddlewares = (middleware, app) => {
|
|
52
76
|
middleware.forEach((middlewareItem) => {
|
|
53
|
-
const middlewareFunc = typeof middlewareItem === "string" ? (0,
|
|
77
|
+
const middlewareFunc = typeof middlewareItem === "string" ? (0, _utils.compatRequire)(middlewareItem) : middlewareItem;
|
|
54
78
|
app.use(middlewareFunc);
|
|
55
79
|
});
|
|
56
80
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
const _default = () => {
|
|
82
|
+
return {
|
|
83
|
+
name: "@modern-js/plugin-koa",
|
|
84
|
+
pre: [
|
|
85
|
+
"@modern-js/plugin-bff"
|
|
86
|
+
],
|
|
87
|
+
post: [
|
|
88
|
+
"@modern-js/plugin-server"
|
|
89
|
+
],
|
|
90
|
+
setup: (api) => {
|
|
91
|
+
return {
|
|
92
|
+
async prepareApiServer({ pwd, config, render }) {
|
|
93
|
+
var _userConfig_bff;
|
|
94
|
+
let app;
|
|
95
|
+
const router = new _koarouter.default();
|
|
96
|
+
const apiDir = _path.join(pwd, "./api");
|
|
97
|
+
const appContext = api.useAppContext();
|
|
98
|
+
const apiHandlerInfos = appContext.apiHandlerInfos;
|
|
99
|
+
const mode = appContext.apiMode;
|
|
100
|
+
const userConfig = api.useConfigContext();
|
|
101
|
+
if (mode === "framework") {
|
|
102
|
+
app = await findAppModule(apiDir);
|
|
103
|
+
if (!(app instanceof _koa.default)) {
|
|
104
|
+
app = new _koa.default();
|
|
105
|
+
app.use((0, _koabody.default)({
|
|
106
|
+
multipart: true
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
if (config) {
|
|
110
|
+
const { middleware } = config;
|
|
111
|
+
initMiddlewares(middleware, app);
|
|
112
|
+
}
|
|
113
|
+
app.use(_context.run);
|
|
114
|
+
(0, _registerRoutes.default)(router, apiHandlerInfos);
|
|
115
|
+
} else if (mode === "function") {
|
|
116
|
+
app = new _koa.default();
|
|
117
|
+
app.use((0, _koabody.default)({
|
|
77
118
|
multipart: true
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else if (mode === "function") {
|
|
88
|
-
app = new import_koa.default();
|
|
89
|
-
app.use(
|
|
90
|
-
(0, import_koa_body.default)({
|
|
91
|
-
multipart: true
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
if (config) {
|
|
95
|
-
const { middleware } = config;
|
|
96
|
-
initMiddlewares(middleware, app);
|
|
97
|
-
}
|
|
98
|
-
app.use(import_context.run);
|
|
99
|
-
(0, import_registerRoutes.default)(router, apiHandlerInfos);
|
|
100
|
-
} else {
|
|
101
|
-
throw new Error(`mode must be function or framework`);
|
|
102
|
-
}
|
|
103
|
-
app.use(router.routes());
|
|
104
|
-
if (((_a = userConfig.bff) == null ? void 0 : _a.enableHandleWeb) && render) {
|
|
105
|
-
app.use(async (ctx, next) => {
|
|
106
|
-
const html = await render(ctx.req, ctx.res);
|
|
107
|
-
if (html) {
|
|
108
|
-
ctx.body = html;
|
|
119
|
+
}));
|
|
120
|
+
if (config) {
|
|
121
|
+
const { middleware } = config;
|
|
122
|
+
initMiddlewares(middleware, app);
|
|
123
|
+
}
|
|
124
|
+
app.use(_context.run);
|
|
125
|
+
(0, _registerRoutes.default)(router, apiHandlerInfos);
|
|
126
|
+
} else {
|
|
127
|
+
throw new Error(`mode must be function or framework`);
|
|
109
128
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const userConfig = api.useConfigContext();
|
|
120
|
-
if (!((_a = userConfig == null ? void 0 : userConfig.server) == null ? void 0 : _a.enableFrameworkExt)) {
|
|
121
|
-
return next();
|
|
122
|
-
}
|
|
123
|
-
const app = new import_koa.default();
|
|
124
|
-
app.use(async (ctx, next2) => {
|
|
125
|
-
await next2();
|
|
126
|
-
if (!ctx.body) {
|
|
127
|
-
if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
|
|
128
|
-
ctx.res.statusCode = 200;
|
|
129
|
+
app.use(router.routes());
|
|
130
|
+
if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
|
|
131
|
+
app.use(async (ctx, next) => {
|
|
132
|
+
const html = await render(ctx.req, ctx.res);
|
|
133
|
+
if (html) {
|
|
134
|
+
ctx.body = html;
|
|
135
|
+
}
|
|
136
|
+
await next();
|
|
137
|
+
});
|
|
129
138
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
return (req, res) => {
|
|
140
|
+
return Promise.resolve(app.callback()(req, res));
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
prepareWebServer({ config }, next) {
|
|
144
|
+
var _userConfig_server;
|
|
145
|
+
const userConfig = api.useConfigContext();
|
|
146
|
+
if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
|
|
147
|
+
return next();
|
|
148
|
+
}
|
|
149
|
+
const app = new _koa.default();
|
|
150
|
+
app.use(async (ctx, next2) => {
|
|
151
|
+
await next2();
|
|
152
|
+
if (!ctx.body) {
|
|
153
|
+
if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
|
|
154
|
+
ctx.res.statusCode = 200;
|
|
155
|
+
}
|
|
156
|
+
ctx.respond = false;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
app.use((0, _koabody.default)());
|
|
160
|
+
if (config) {
|
|
161
|
+
const { middleware } = config;
|
|
162
|
+
initMiddlewares(middleware, app);
|
|
145
163
|
}
|
|
146
|
-
|
|
147
|
-
|
|
164
|
+
return (ctx) => {
|
|
165
|
+
const { source: { req, res } } = ctx;
|
|
166
|
+
app.on("error", (err) => {
|
|
167
|
+
if (err) {
|
|
168
|
+
throw err;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return Promise.resolve(app.callback()(req, res));
|
|
172
|
+
};
|
|
173
|
+
}
|
|
148
174
|
};
|
|
149
175
|
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
-
0 && (module.exports = {});
|
|
176
|
+
};
|
|
177
|
+
};
|
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var registerRoutes_exports = {};
|
|
19
|
-
__export(registerRoutes_exports, {
|
|
20
|
-
default: () => registerRoutes_default
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _default
|
|
21
8
|
});
|
|
22
|
-
|
|
23
|
-
var import_utils = require("./utils");
|
|
9
|
+
const _utils = require("./utils");
|
|
24
10
|
const registerRoutes = (router, handlerInfos) => {
|
|
25
11
|
handlerInfos.forEach(({ routePath, handler, httpMethod }) => {
|
|
26
|
-
const routeHandler = (0,
|
|
12
|
+
const routeHandler = (0, _utils.createRouteHandler)(handler);
|
|
27
13
|
const method = httpMethod.toLowerCase();
|
|
28
14
|
router[method](routePath, routeHandler);
|
|
29
15
|
});
|
|
30
16
|
};
|
|
31
|
-
|
|
32
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
-
0 && (module.exports = {});
|
|
17
|
+
const _default = registerRoutes;
|