@modern-js/plugin-bff 2.69.4 → 3.0.0-alpha.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/dist/cjs/cli.js +256 -272
- package/dist/cjs/constants.js +43 -34
- package/dist/cjs/index.js +55 -19
- package/dist/cjs/loader.js +69 -65
- package/dist/cjs/runtime/create-request/index.js +39 -29
- package/dist/cjs/runtime/hono/adapter.js +128 -126
- package/dist/cjs/runtime/hono/index.js +78 -30
- package/dist/cjs/runtime/hono/operators.js +64 -67
- package/dist/cjs/server.js +159 -165
- package/dist/cjs/utils/clientGenerator.js +204 -206
- package/dist/cjs/utils/createHonoRoutes.js +128 -144
- package/dist/cjs/utils/crossProjectApiPlugin.js +91 -81
- package/dist/cjs/utils/pluginGenerator.js +66 -54
- package/dist/cjs/utils/runtimeGenerator.js +67 -45
- package/dist/esm/cli.mjs +214 -0
- package/dist/esm/constants.mjs +11 -0
- package/dist/esm/loader.mjs +39 -0
- package/dist/esm/runtime/create-request/{index.js → index.mjs} +1 -5
- package/dist/esm/runtime/hono/adapter.mjs +95 -0
- package/dist/{esm-node/runtime/hono/index.js → esm/runtime/hono/index.mjs} +2 -4
- package/dist/esm/runtime/hono/operators.mjs +31 -0
- package/dist/esm/server.mjs +122 -0
- package/dist/esm/utils/clientGenerator.mjs +175 -0
- package/dist/esm/utils/createHonoRoutes.mjs +91 -0
- package/dist/esm/utils/crossProjectApiPlugin.mjs +34 -0
- package/dist/esm/utils/pluginGenerator.mjs +29 -0
- package/dist/esm/utils/runtimeGenerator.mjs +43 -0
- package/dist/esm-node/cli.mjs +214 -0
- package/dist/esm-node/constants.mjs +11 -0
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/loader.mjs +39 -0
- package/dist/esm-node/runtime/create-request/{index.js → index.mjs} +1 -5
- package/dist/esm-node/runtime/hono/adapter.mjs +95 -0
- package/dist/{esm/runtime/hono/index.js → esm-node/runtime/hono/index.mjs} +3 -5
- package/dist/esm-node/runtime/hono/operators.mjs +31 -0
- package/dist/esm-node/server.mjs +122 -0
- package/dist/esm-node/utils/clientGenerator.mjs +175 -0
- package/dist/esm-node/utils/createHonoRoutes.mjs +91 -0
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +34 -0
- package/dist/esm-node/utils/pluginGenerator.mjs +29 -0
- package/dist/esm-node/utils/runtimeGenerator.mjs +43 -0
- package/dist/types/loader.d.ts +2 -2
- package/dist/types/runtime/hono/adapter.d.ts +3 -3
- package/dist/types/server.d.ts +2 -2
- package/dist/types/utils/runtimeGenerator.d.ts +2 -1
- package/package.json +54 -32
- package/rslib.config.mts +4 -0
- package/dist/cjs/helper.js +0 -48
- package/dist/esm/cli.js +0 -425
- package/dist/esm/constants.js +0 -14
- package/dist/esm/helper.js +0 -13
- package/dist/esm/index.js +0 -1
- package/dist/esm/loader.js +0 -75
- package/dist/esm/runtime/hono/adapter.js +0 -243
- package/dist/esm/runtime/hono/operators.js +0 -79
- package/dist/esm/server.js +0 -258
- package/dist/esm/utils/clientGenerator.js +0 -517
- package/dist/esm/utils/createHonoRoutes.js +0 -319
- package/dist/esm/utils/crossProjectApiPlugin.js +0 -49
- package/dist/esm/utils/pluginGenerator.js +0 -94
- package/dist/esm/utils/runtimeGenerator.js +0 -55
- package/dist/esm-node/cli.js +0 -246
- package/dist/esm-node/constants.js +0 -14
- package/dist/esm-node/helper.js +0 -14
- package/dist/esm-node/loader.js +0 -49
- package/dist/esm-node/runtime/hono/adapter.js +0 -103
- package/dist/esm-node/runtime/hono/operators.js +0 -46
- package/dist/esm-node/server.js +0 -142
- package/dist/esm-node/utils/clientGenerator.js +0 -192
- package/dist/esm-node/utils/createHonoRoutes.js +0 -120
- package/dist/esm-node/utils/crossProjectApiPlugin.js +0 -47
- package/dist/esm-node/utils/pluginGenerator.js +0 -31
- package/dist/esm-node/utils/runtimeGenerator.js +0 -35
- package/dist/types/helper.d.ts +0 -2
- package/types.d.ts +0 -3
- /package/dist/{esm-node/index.js → esm/index.mjs} +0 -0
|
@@ -1,33 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./operators" (module) {
|
|
4
|
+
module.exports = require("./operators.js");
|
|
5
|
+
},
|
|
6
|
+
"@modern-js/bff-core" (module) {
|
|
7
|
+
module.exports = require("@modern-js/bff-core");
|
|
8
|
+
},
|
|
9
|
+
"@modern-js/server-core" (module) {
|
|
10
|
+
module.exports = require("@modern-js/server-core");
|
|
11
|
+
}
|
|
9
12
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
var __webpack_module_cache__ = {};
|
|
14
|
+
function __webpack_require__(moduleId) {
|
|
15
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
16
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
17
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
18
|
+
exports: {}
|
|
19
|
+
};
|
|
20
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
21
|
+
return module.exports;
|
|
22
|
+
}
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.n = (module)=>{
|
|
25
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
26
|
+
__webpack_require__.d(getter, {
|
|
27
|
+
a: getter
|
|
28
|
+
});
|
|
29
|
+
return getter;
|
|
30
|
+
};
|
|
31
|
+
})();
|
|
32
|
+
(()=>{
|
|
33
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
34
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: definition[key]
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
42
|
+
})();
|
|
43
|
+
(()=>{
|
|
44
|
+
__webpack_require__.r = (exports1)=>{
|
|
45
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
46
|
+
value: 'Module'
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
49
|
+
value: true
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
var __webpack_exports__ = {};
|
|
54
|
+
(()=>{
|
|
55
|
+
__webpack_require__.r(__webpack_exports__);
|
|
56
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
57
|
+
useHonoContext: ()=>_modern_js_server_core__rspack_import_1.useHonoContext
|
|
58
|
+
});
|
|
59
|
+
var _modern_js_bff_core__rspack_import_0 = __webpack_require__("@modern-js/bff-core");
|
|
60
|
+
var __rspack_reexport = {};
|
|
61
|
+
for(const __rspack_import_key in _modern_js_bff_core__rspack_import_0)if ([
|
|
62
|
+
"useHonoContext",
|
|
63
|
+
"default"
|
|
64
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_bff_core__rspack_import_0[__rspack_import_key];
|
|
65
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
66
|
+
var _modern_js_server_core__rspack_import_1 = __webpack_require__("@modern-js/server-core");
|
|
67
|
+
var _operators__rspack_import_2 = __webpack_require__("./operators");
|
|
68
|
+
var __rspack_reexport = {};
|
|
69
|
+
for(const __rspack_import_key in _operators__rspack_import_2)if ([
|
|
70
|
+
"useHonoContext",
|
|
71
|
+
"default"
|
|
72
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_operators__rspack_import_2[__rspack_import_key];
|
|
73
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
74
|
+
})();
|
|
75
|
+
exports.useHonoContext = __webpack_exports__.useHonoContext;
|
|
76
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
77
|
+
"useHonoContext"
|
|
78
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
79
|
+
Object.defineProperty(exports, '__esModule', {
|
|
80
|
+
value: true
|
|
33
81
|
});
|
|
@@ -1,71 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
Middleware: ()=>Middleware,
|
|
28
|
+
Pipe: ()=>Pipe
|
|
23
29
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!isPiped) {
|
|
45
|
-
if (output) {
|
|
46
|
-
return executeHelper.result = output;
|
|
47
|
-
} else {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
30
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
31
|
+
const Pipe = (func)=>({
|
|
32
|
+
name: 'pipe',
|
|
33
|
+
async execute (executeHelper, next) {
|
|
34
|
+
const { inputs } = executeHelper;
|
|
35
|
+
const ctx = (0, server_core_namespaceObject.useHonoContext)();
|
|
36
|
+
const { res } = ctx;
|
|
37
|
+
if ('function' == typeof func) {
|
|
38
|
+
let isPiped = true;
|
|
39
|
+
const end = (value)=>{
|
|
40
|
+
isPiped = false;
|
|
41
|
+
if ('function' == typeof value) return void value(res);
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
const output = await func(inputs, end);
|
|
45
|
+
if (!isPiped) if (output) return executeHelper.result = output;
|
|
46
|
+
else return;
|
|
47
|
+
executeHelper.inputs = output;
|
|
48
|
+
await next();
|
|
49
|
+
}
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
0 && (module.exports = {
|
|
69
|
-
Middleware,
|
|
70
|
-
Pipe
|
|
51
|
+
});
|
|
52
|
+
const Middleware = (middleware)=>({
|
|
53
|
+
name: 'middleware',
|
|
54
|
+
metadata (helper) {
|
|
55
|
+
const middlewares = helper.getMetadata('pipe') || [];
|
|
56
|
+
middlewares.push(middleware);
|
|
57
|
+
helper.setMetadata('middleware', middlewares);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
exports.Middleware = __webpack_exports__.Middleware;
|
|
61
|
+
exports.Pipe = __webpack_exports__.Pipe;
|
|
62
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
63
|
+
"Middleware",
|
|
64
|
+
"Pipe"
|
|
65
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
66
|
+
Object.defineProperty(exports, '__esModule', {
|
|
67
|
+
value: true
|
|
71
68
|
});
|
package/dist/cjs/server.js
CHANGED
|
@@ -1,172 +1,166 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
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 server_exports = {};
|
|
30
|
-
__export(server_exports, {
|
|
31
|
-
default: () => server_default
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(server_exports);
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_bff_core = require("@modern-js/bff-core");
|
|
36
|
-
var import_utils = require("@modern-js/utils");
|
|
37
|
-
var import_utils2 = require("@modern-js/utils");
|
|
38
|
-
var import_constants = require("./constants");
|
|
39
|
-
var import_adapter = require("./runtime/hono/adapter");
|
|
40
|
-
class Storage {
|
|
41
|
-
reset() {
|
|
42
|
-
this.middlewares = [];
|
|
43
|
-
}
|
|
44
|
-
constructor() {
|
|
45
|
-
this.middlewares = [];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const createTransformAPI = (storage) => ({
|
|
49
|
-
addMiddleware(fn) {
|
|
50
|
-
storage.middlewares.push(fn);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
var server_default = () => ({
|
|
54
|
-
name: "@modern-js/plugin-bff",
|
|
55
|
-
setup: (api) => {
|
|
56
|
-
const storage = new Storage();
|
|
57
|
-
const transformAPI = createTransformAPI(storage);
|
|
58
|
-
let apiAppPath = "";
|
|
59
|
-
let apiRouter;
|
|
60
|
-
const honoAdapter = new import_adapter.HonoAdapter(api);
|
|
61
|
-
return {
|
|
62
|
-
async prepare() {
|
|
63
|
-
var _config_bff, _config_bff1, _config_bff2;
|
|
64
|
-
const appContext = api.useAppContext();
|
|
65
|
-
const { appDirectory, distDirectory, render } = appContext;
|
|
66
|
-
const root = (0, import_utils.isProd)() ? distDirectory : appDirectory;
|
|
67
|
-
const apiPath = import_path.default.resolve(root || process.cwd(), import_utils.API_DIR);
|
|
68
|
-
apiAppPath = import_path.default.resolve(apiPath, import_constants.API_APP_NAME);
|
|
69
|
-
const apiMod = await (0, import_utils.requireExistModule)(apiAppPath);
|
|
70
|
-
if (apiMod && typeof apiMod === "function") {
|
|
71
|
-
apiMod(transformAPI);
|
|
72
|
-
}
|
|
73
|
-
const { middlewares } = storage;
|
|
74
|
-
api.setAppContext({
|
|
75
|
-
...appContext,
|
|
76
|
-
apiMiddlewares: middlewares
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
77
8
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
handler = async (c, next) => {
|
|
87
|
-
c.body("");
|
|
88
|
-
await next();
|
|
89
|
-
};
|
|
90
|
-
} else {
|
|
91
|
-
const runner = api.useHookRunners();
|
|
92
|
-
const renderHandler = enableHandleWeb ? render : null;
|
|
93
|
-
handler = await runner.prepareApiServer({
|
|
94
|
-
pwd,
|
|
95
|
-
prefix,
|
|
96
|
-
render: renderHandler,
|
|
97
|
-
httpMethodDecider
|
|
98
|
-
}, {
|
|
99
|
-
onLast: () => null
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (handler && (0, import_utils2.isFunction)(handler)) {
|
|
103
|
-
globalMiddlewares.push({
|
|
104
|
-
name: "bind-bff",
|
|
105
|
-
handler: (c, next) => {
|
|
106
|
-
if (!c.req.path.startsWith(prefix) && !enableHandleWeb) {
|
|
107
|
-
return next();
|
|
108
|
-
} else {
|
|
109
|
-
return handler(c, next);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
order: "post",
|
|
113
|
-
before: [
|
|
114
|
-
"custom-server-hook",
|
|
115
|
-
"custom-server-middleware",
|
|
116
|
-
"render"
|
|
117
|
-
]
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
honoAdapter.registerMiddleware({
|
|
121
|
-
prefix,
|
|
122
|
-
enableHandleWeb
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
async reset({ event }) {
|
|
126
|
-
storage.reset();
|
|
127
|
-
const appContext = api.useAppContext();
|
|
128
|
-
const newApiModule = await (0, import_utils.requireExistModule)(apiAppPath);
|
|
129
|
-
if (newApiModule && typeof newApiModule === "function") {
|
|
130
|
-
newApiModule(transformAPI);
|
|
131
|
-
}
|
|
132
|
-
const { middlewares } = storage;
|
|
133
|
-
api.setAppContext({
|
|
134
|
-
...appContext,
|
|
135
|
-
apiMiddlewares: middlewares
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
136
17
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
async prepareApiServer(props, next) {
|
|
149
|
-
const { pwd, prefix, httpMethodDecider } = props;
|
|
150
|
-
const apiDir = import_path.default.resolve(pwd, import_utils.API_DIR);
|
|
151
|
-
const appContext = api.useAppContext();
|
|
152
|
-
const { apiDirectory, lambdaDirectory } = appContext;
|
|
153
|
-
apiRouter = new import_bff_core.ApiRouter({
|
|
154
|
-
appDir: pwd,
|
|
155
|
-
apiDir: apiDirectory || apiDir,
|
|
156
|
-
lambdaDir: lambdaDirectory,
|
|
157
|
-
prefix,
|
|
158
|
-
httpMethodDecider
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
159
27
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
api.setAppContext({
|
|
163
|
-
...appContext,
|
|
164
|
-
apiRouter,
|
|
165
|
-
apiHandlerInfos,
|
|
166
|
-
apiMode
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
167
30
|
});
|
|
168
|
-
return next(props);
|
|
169
|
-
}
|
|
170
31
|
};
|
|
171
|
-
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
default: ()=>server
|
|
37
|
+
});
|
|
38
|
+
const external_path_namespaceObject = require("path");
|
|
39
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
40
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
41
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
42
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
43
|
+
const adapter_js_namespaceObject = require("./runtime/hono/adapter.js");
|
|
44
|
+
class Storage {
|
|
45
|
+
reset() {
|
|
46
|
+
this.middlewares = [];
|
|
47
|
+
}
|
|
48
|
+
constructor(){
|
|
49
|
+
this.middlewares = [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const createTransformAPI = (storage)=>({
|
|
53
|
+
addMiddleware (fn) {
|
|
54
|
+
storage.middlewares.push(fn);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const server = ()=>({
|
|
58
|
+
name: '@modern-js/plugin-bff',
|
|
59
|
+
setup: (api)=>{
|
|
60
|
+
const storage = new Storage();
|
|
61
|
+
const transformAPI = createTransformAPI(storage);
|
|
62
|
+
let apiAppPath = '';
|
|
63
|
+
let apiRouter;
|
|
64
|
+
const honoAdapter = new adapter_js_namespaceObject.HonoAdapter(api);
|
|
65
|
+
api.onPrepare(async ()=>{
|
|
66
|
+
const appContext = api.getServerContext();
|
|
67
|
+
const { appDirectory, distDirectory, render } = appContext;
|
|
68
|
+
const root = (0, utils_namespaceObject.isProd)() ? distDirectory : appDirectory;
|
|
69
|
+
const apiPath = external_path_default().resolve(root || process.cwd(), utils_namespaceObject.API_DIR);
|
|
70
|
+
apiAppPath = external_path_default().resolve(apiPath, external_constants_js_namespaceObject.API_APP_NAME);
|
|
71
|
+
const apiMod = await (0, utils_namespaceObject.requireExistModule)(apiAppPath);
|
|
72
|
+
if (apiMod && 'function' == typeof apiMod) apiMod(transformAPI);
|
|
73
|
+
const { middlewares } = storage;
|
|
74
|
+
api.updateServerContext({
|
|
75
|
+
...appContext,
|
|
76
|
+
apiMiddlewares: middlewares
|
|
77
|
+
});
|
|
78
|
+
const config = api.getServerConfig();
|
|
79
|
+
const prefix = config?.bff?.prefix || '/api';
|
|
80
|
+
const enableHandleWeb = config?.bff?.enableHandleWeb;
|
|
81
|
+
const httpMethodDecider = config?.bff?.httpMethodDecider;
|
|
82
|
+
const { distDirectory: pwd, middlewares: globalMiddlewares } = api.getServerContext();
|
|
83
|
+
const webOnly = await (0, utils_namespaceObject.isWebOnly)();
|
|
84
|
+
let handler;
|
|
85
|
+
if (webOnly) handler = async (c, next)=>{
|
|
86
|
+
c.body('');
|
|
87
|
+
await next();
|
|
88
|
+
};
|
|
89
|
+
else {
|
|
90
|
+
const runner = api.getHooks();
|
|
91
|
+
const renderHandler = enableHandleWeb ? render : null;
|
|
92
|
+
handler = await runner.prepareApiServer.call({
|
|
93
|
+
pwd: pwd,
|
|
94
|
+
prefix,
|
|
95
|
+
render: renderHandler,
|
|
96
|
+
httpMethodDecider
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (handler && (0, utils_namespaceObject.isFunction)(handler)) globalMiddlewares.push({
|
|
100
|
+
name: 'bind-bff',
|
|
101
|
+
handler: (c, next)=>{
|
|
102
|
+
if (!c.req.path.startsWith(prefix) && !enableHandleWeb) return next();
|
|
103
|
+
return handler(c, next);
|
|
104
|
+
},
|
|
105
|
+
order: 'post',
|
|
106
|
+
before: [
|
|
107
|
+
'custom-server-hook',
|
|
108
|
+
'custom-server-middleware',
|
|
109
|
+
'render'
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
honoAdapter.registerMiddleware({
|
|
113
|
+
prefix,
|
|
114
|
+
enableHandleWeb
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
api.onReset(async ({ event })=>{
|
|
118
|
+
storage.reset();
|
|
119
|
+
const appContext = api.getServerContext();
|
|
120
|
+
const newApiModule = await (0, utils_namespaceObject.requireExistModule)(apiAppPath);
|
|
121
|
+
if (newApiModule && 'function' == typeof newApiModule) newApiModule(transformAPI);
|
|
122
|
+
const { middlewares } = storage;
|
|
123
|
+
api.updateServerContext({
|
|
124
|
+
...appContext,
|
|
125
|
+
apiMiddlewares: middlewares
|
|
126
|
+
});
|
|
127
|
+
if ('file-change' === event.type) {
|
|
128
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
129
|
+
const appContext = api.getServerContext();
|
|
130
|
+
api.updateServerContext({
|
|
131
|
+
...appContext,
|
|
132
|
+
apiHandlerInfos
|
|
133
|
+
});
|
|
134
|
+
await honoAdapter.setHandlers();
|
|
135
|
+
await honoAdapter.registerApiRoutes();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
api.prepareApiServer(async (input, next)=>{
|
|
139
|
+
const { pwd, prefix, httpMethodDecider } = input;
|
|
140
|
+
const apiDir = external_path_default().resolve(pwd, utils_namespaceObject.API_DIR);
|
|
141
|
+
const appContext = api.getServerContext();
|
|
142
|
+
const { apiDirectory, lambdaDirectory } = appContext;
|
|
143
|
+
apiRouter = new bff_core_namespaceObject.ApiRouter({
|
|
144
|
+
appDir: pwd,
|
|
145
|
+
apiDir: apiDirectory || apiDir,
|
|
146
|
+
lambdaDir: lambdaDirectory,
|
|
147
|
+
prefix,
|
|
148
|
+
httpMethodDecider
|
|
149
|
+
});
|
|
150
|
+
const apiHandlerInfos = await apiRouter.getApiHandlers();
|
|
151
|
+
api.updateServerContext({
|
|
152
|
+
...appContext,
|
|
153
|
+
apiRouter,
|
|
154
|
+
apiHandlerInfos
|
|
155
|
+
});
|
|
156
|
+
return next(input);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
exports["default"] = __webpack_exports__["default"];
|
|
161
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
162
|
+
"default"
|
|
163
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
164
|
+
Object.defineProperty(exports, '__esModule', {
|
|
165
|
+
value: true
|
|
172
166
|
});
|