@modern-js/plugin-express 2.15.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @modern-js/plugin-express
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
+
3
19
  ## 2.15.0
4
20
 
5
21
  ### Patch Changes
@@ -1,51 +1,67 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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 __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
- module.exports = __toCommonJS(cli_exports);
33
- var path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
35
- var import_bff_core = require("@modern-js/bff-core");
36
- var cli_default = () => ({
9
+ const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ const _bffcore = require("@modern-js/bff-core");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function")
14
+ return null;
15
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
16
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop2) {
18
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for (var key in obj) {
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ const _default = () => ({
37
53
  name: "@modern-js/plugin-express",
38
54
  setup: (api) => {
39
55
  let bffExportsUtils;
40
56
  const { useAppContext } = api;
41
- const runtimeModulePath = path.resolve(__dirname, "../runtime");
57
+ const runtimeModulePath = _path.resolve(__dirname, "../runtime");
42
58
  return {
43
59
  config() {
44
60
  const appContext = useAppContext();
45
61
  const { appDirectory } = appContext;
46
- bffExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "server");
62
+ bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "server");
47
63
  const serverRuntimePath = bffExportsUtils.getPath();
48
- const relativeRuntimePath = (0, import_bff_core.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
64
+ const relativeRuntimePath = (0, _bffcore.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
49
65
  if (process.env.NODE_ENV === "production") {
50
66
  return {
51
67
  source: {
@@ -76,8 +92,8 @@ var cli_default = () => ({
76
92
  },
77
93
  addRuntimeExports(input) {
78
94
  const currentFile = bffExportsUtils.getPath();
79
- const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
80
- const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve("express"));
95
+ const relativeRuntimeModulePath = _path.relative(_path.dirname(currentFile), runtimeModulePath);
96
+ const relativeFramePath = _path.relative(_path.dirname(currentFile), require.resolve("express"));
81
97
  bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
82
98
  const express = require('${relativeFramePath}')
83
99
  module.exports = {
@@ -90,5 +106,3 @@ var cli_default = () => ({
90
106
  };
91
107
  }
92
108
  });
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {});
@@ -1,30 +1,17 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
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
- __defProp(target, name, { get: all[name], enumerable: true });
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 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
- module.exports = __toCommonJS(context_exports);
24
- var import_bff_core = require("@modern-js/bff-core");
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
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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
- module.exports = __toCommonJS(src_exports);
34
- var import_plugin = __toESM(require("./plugin"));
35
- __reExport(src_exports, require("./context"), module.exports);
36
- var src_default = import_plugin.default;
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {});
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;
@@ -1,54 +1,75 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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 __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
- module.exports = __toCommonJS(plugin_exports);
33
- var path = __toESM(require("path"));
34
- var import_express = __toESM(require("express"));
35
- var import_cookie_parser = __toESM(require("cookie-parser"));
36
- var import_utils = require("@modern-js/utils");
37
- var import_finalhandler = __toESM(require("finalhandler"));
38
- var import_context = require("./context");
39
- var import_registerRoutes = __toESM(require("./registerRoutes"));
40
- const debug = (0, import_utils.createDebugger)("express");
9
+ const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
10
+ const _express = /* @__PURE__ */ _interop_require_default(require("express"));
11
+ const _cookieparser = /* @__PURE__ */ _interop_require_default(require("cookie-parser"));
12
+ const _utils = require("@modern-js/utils");
13
+ const _finalhandler = /* @__PURE__ */ _interop_require_default(require("finalhandler"));
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
+ }
61
+ const debug = (0, _utils.createDebugger)("express");
41
62
  const findAppModule = async (apiDir) => {
42
63
  const exts = [
43
64
  ".ts",
44
65
  ".js"
45
66
  ];
46
- const paths = exts.map((ext) => path.resolve(apiDir, `app${ext}`));
67
+ const paths = exts.map((ext) => _path.resolve(apiDir, `app${ext}`));
47
68
  for (const filename of paths) {
48
- if (await import_utils.fs.pathExists(filename)) {
69
+ if (await _utils.fs.pathExists(filename)) {
49
70
  delete require.cache[filename];
50
71
  return [
51
- (0, import_utils.compatRequire)(filename),
72
+ (0, _utils.compatRequire)(filename),
52
73
  require(filename)
53
74
  ];
54
75
  }
@@ -57,136 +78,138 @@ const findAppModule = async (apiDir) => {
57
78
  };
58
79
  const initMiddlewares = (middleware, app) => {
59
80
  middleware.forEach((middlewareItem) => {
60
- const middlewareFunc = typeof middlewareItem === "string" ? (0, import_utils.compatRequire)(middlewareItem) : middlewareItem;
81
+ const middlewareFunc = typeof middlewareItem === "string" ? (0, _utils.compatRequire)(middlewareItem) : middlewareItem;
61
82
  app.use(middlewareFunc);
62
83
  });
63
84
  };
64
85
  const useRun = (app) => {
65
86
  app.use((req, res, next) => {
66
- (0, import_context.run)({
87
+ (0, _context.run)({
67
88
  req,
68
89
  res
69
90
  }, next);
70
91
  });
71
92
  };
72
93
  const initApp = (app) => {
73
- app.use((0, import_cookie_parser.default)());
74
- app.use(import_express.default.text());
75
- app.use(import_express.default.urlencoded({
94
+ app.use((0, _cookieparser.default)());
95
+ app.use(_express.default.text());
96
+ app.use(_express.default.urlencoded({
76
97
  extended: true
77
98
  }));
78
- app.use(import_express.default.json());
99
+ app.use(_express.default.json());
79
100
  return app;
80
101
  };
81
- var plugin_default = () => ({
82
- name: "@modern-js/plugin-express",
83
- pre: [
84
- "@modern-js/plugin-bff"
85
- ],
86
- post: [
87
- "@modern-js/plugin-server"
88
- ],
89
- setup: (api) => ({
90
- async prepareApiServer({ pwd, config, render }) {
91
- var _a;
92
- let app;
93
- const appContext = api.useAppContext();
94
- const apiHandlerInfos = appContext.apiHandlerInfos;
95
- const apiDirectory = appContext.apiDirectory;
96
- const apiDir = apiDirectory || path.join(pwd, "./api");
97
- const mode = appContext.apiMode;
98
- const userConfig = api.useConfigContext();
99
- if (mode === "framework") {
100
- const appModule = await findAppModule(apiDir);
101
- app = appModule[0];
102
- const hooks = appModule[1];
103
- if (!app || !app.use) {
104
- app = (0, import_express.default)();
105
- }
106
- initApp(app);
107
- if (config) {
108
- const { middleware } = config;
109
- initMiddlewares(middleware, app);
110
- }
111
- useRun(app);
112
- (0, import_registerRoutes.default)(app, apiHandlerInfos);
113
- if (hooks) {
114
- const { afterLambdaRegisted } = hooks;
115
- if (afterLambdaRegisted) {
116
- afterLambdaRegisted(app);
102
+ const _default = () => {
103
+ return {
104
+ name: "@modern-js/plugin-express",
105
+ pre: [
106
+ "@modern-js/plugin-bff"
107
+ ],
108
+ post: [
109
+ "@modern-js/plugin-server"
110
+ ],
111
+ setup: (api) => {
112
+ return {
113
+ async prepareApiServer({ pwd, config, render }) {
114
+ var _userConfig_bff;
115
+ let app;
116
+ const appContext = api.useAppContext();
117
+ const apiHandlerInfos = appContext.apiHandlerInfos;
118
+ const apiDirectory = appContext.apiDirectory;
119
+ const apiDir = apiDirectory || _path.join(pwd, "./api");
120
+ const mode = appContext.apiMode;
121
+ const userConfig = api.useConfigContext();
122
+ if (mode === "framework") {
123
+ const appModule = await findAppModule(apiDir);
124
+ app = appModule[0];
125
+ const hooks = appModule[1];
126
+ if (!app || !app.use) {
127
+ app = (0, _express.default)();
128
+ }
129
+ initApp(app);
130
+ if (config) {
131
+ const { middleware } = config;
132
+ initMiddlewares(middleware, app);
133
+ }
134
+ useRun(app);
135
+ (0, _registerRoutes.default)(app, apiHandlerInfos);
136
+ if (hooks) {
137
+ const { afterLambdaRegisted } = hooks;
138
+ if (afterLambdaRegisted) {
139
+ afterLambdaRegisted(app);
140
+ }
141
+ }
142
+ } else if (mode === "function") {
143
+ app = (0, _express.default)();
144
+ initApp(app);
145
+ if (config) {
146
+ const { middleware } = config;
147
+ initMiddlewares(middleware, app);
148
+ }
149
+ useRun(app);
150
+ (0, _registerRoutes.default)(app, apiHandlerInfos);
151
+ } else {
152
+ throw new Error(`mode must be function or framework`);
117
153
  }
118
- }
119
- } else if (mode === "function") {
120
- app = (0, import_express.default)();
121
- initApp(app);
122
- if (config) {
123
- const { middleware } = config;
124
- initMiddlewares(middleware, app);
125
- }
126
- useRun(app);
127
- (0, import_registerRoutes.default)(app, apiHandlerInfos);
128
- } else {
129
- throw new Error(`mode must be function or framework`);
130
- }
131
- if (((_a = userConfig.bff) == null ? void 0 : _a.enableHandleWeb) && render) {
132
- app.use(async (req, res, next) => {
133
- const html = await render(req, res);
134
- if (html) {
135
- res.end(html);
154
+ if (((_userConfig_bff = userConfig.bff) === null || _userConfig_bff === void 0 ? void 0 : _userConfig_bff.enableHandleWeb) && render) {
155
+ app.use(async (req, res, next) => {
156
+ const html = await render(req, res);
157
+ if (html) {
158
+ res.end(html);
159
+ }
160
+ next();
161
+ });
136
162
  }
137
- next();
138
- });
139
- }
140
- return (req, res) => new Promise((resolve, reject) => {
141
- const handler = (err) => {
142
- if (err) {
143
- return reject(err);
163
+ return (req, res) => new Promise((resolve, reject) => {
164
+ const handler = (err) => {
165
+ if (err) {
166
+ return reject(err);
167
+ }
168
+ return (0, _finalhandler.default)(req, res, {})(null);
169
+ };
170
+ res.on("finish", (err) => {
171
+ if (err) {
172
+ return reject(err);
173
+ }
174
+ return resolve();
175
+ });
176
+ return app(req, res, handler);
177
+ });
178
+ },
179
+ prepareWebServer({ config }, next) {
180
+ var _userConfig_server;
181
+ const userConfig = api.useConfigContext();
182
+ if (!(userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.enableFrameworkExt)) {
183
+ return next();
144
184
  }
145
- return (0, import_finalhandler.default)(req, res, {})(null);
146
- };
147
- res.on("finish", (err) => {
148
- if (err) {
149
- return reject(err);
185
+ const app = (0, _express.default)();
186
+ initApp(app);
187
+ if (config) {
188
+ const { middleware } = config;
189
+ debug("web middleware", middleware);
190
+ initMiddlewares(middleware, app);
150
191
  }
151
- return resolve();
152
- });
153
- return app(req, res, handler);
154
- });
155
- },
156
- prepareWebServer({ config }, next) {
157
- var _a;
158
- const userConfig = api.useConfigContext();
159
- if (!((_a = userConfig == null ? void 0 : userConfig.server) == null ? void 0 : _a.enableFrameworkExt)) {
160
- return next();
161
- }
162
- const app = (0, import_express.default)();
163
- initApp(app);
164
- if (config) {
165
- const { middleware } = config;
166
- debug("web middleware", middleware);
167
- initMiddlewares(middleware, app);
168
- }
169
- return (ctx) => new Promise((resolve, reject) => {
170
- const { source: { req, res } } = ctx;
171
- const handler = (err) => {
172
- if (err) {
173
- return reject(err);
174
- }
175
- if (res.headersSent && res.statusCode !== 200) {
176
- (0, import_finalhandler.default)(req, res, {})(null);
177
- }
178
- return resolve();
179
- };
180
- res.on("finish", (err) => {
181
- if (err) {
182
- return reject(err);
183
- }
184
- return resolve();
185
- });
186
- return app(req, res, handler);
187
- });
192
+ return (ctx) => new Promise((resolve, reject) => {
193
+ const { source: { req, res } } = ctx;
194
+ const handler = (err) => {
195
+ if (err) {
196
+ return reject(err);
197
+ }
198
+ if (res.headersSent && res.statusCode !== 200) {
199
+ (0, _finalhandler.default)(req, res, {})(null);
200
+ }
201
+ return resolve();
202
+ };
203
+ res.on("finish", (err) => {
204
+ if (err) {
205
+ return reject(err);
206
+ }
207
+ return resolve();
208
+ });
209
+ return app(req, res, handler);
210
+ });
211
+ }
212
+ };
188
213
  }
189
- })
190
- });
191
- // Annotate the CommonJS export names for ESM import in node:
192
- 0 && (module.exports = {});
214
+ };
215
+ };