@modern-js/prod-server 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/apply.js CHANGED
@@ -1,97 +1,93 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var apply_exports = {};
20
- __export(apply_exports, {
21
- applyPlugins: () => applyPlugins
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
+ applyPlugins: ()=>applyPlugins
22
28
  });
23
- module.exports = __toCommonJS(apply_exports);
24
- var import_server_core = require("@modern-js/server-core");
25
- var import_node = require("@modern-js/server-core/node");
26
- var import_utils = require("@modern-js/utils");
29
+ const server_core_namespaceObject = require("@modern-js/server-core");
30
+ const node_namespaceObject = require("@modern-js/server-core/node");
31
+ const utils_namespaceObject = require("@modern-js/utils");
27
32
  function getLogger(_) {
28
- if (process.env.DEBUG || process.env.NODE_ENV === "production") {
29
- return (0, import_utils.createLogger)({
30
- level: process.env.MODERN_SERVER_LOG_LEVEL || "verbose"
33
+ if (process.env.DEBUG || 'production' === process.env.NODE_ENV) return (0, utils_namespaceObject.createLogger)({
34
+ level: process.env.MODERN_SERVER_LOG_LEVEL || 'verbose'
31
35
  });
32
- } else {
33
- return (0, import_utils.createLogger)();
34
- }
36
+ return (0, utils_namespaceObject.createLogger)();
35
37
  }
36
38
  async function applyPlugins(serverBase, options, nodeServer) {
37
- var _options_serverConfig;
38
- const { pwd, appContext, config, logger: optLogger } = options;
39
- const serverErrorHandler = (_options_serverConfig = options.serverConfig) === null || _options_serverConfig === void 0 ? void 0 : _options_serverConfig.onError;
40
- const loadCachePwd = (0, import_utils.isProd)() ? pwd : appContext.appDirectory || pwd;
41
- const cacheConfig = await (0, import_node.loadCacheConfig)(loadCachePwd);
42
- serverBase.notFound((c) => {
43
- const monitors = c.get("monitors");
44
- (0, import_server_core.onError)(import_server_core.ErrorDigest.ENOTF, "404 not found", monitors, c.req.raw);
45
- return c.html((0, import_server_core.createErrorHtml)(404), 404);
46
- });
47
- serverBase.onError(async (err, c) => {
48
- var _config_bff;
49
- const monitors = c.get("monitors");
50
- (0, import_server_core.onError)(import_server_core.ErrorDigest.EINTER, err, monitors, c.req.raw);
51
- if (serverErrorHandler) {
52
- try {
53
- const result = await serverErrorHandler(err, c);
54
- if (result instanceof Response) {
55
- return result;
39
+ const { pwd, appContext, config, logger: optLogger } = options;
40
+ const serverErrorHandler = options.serverConfig?.onError;
41
+ const loadCachePwd = (0, utils_namespaceObject.isProd)() ? pwd : appContext.appDirectory || pwd;
42
+ const cacheConfig = await (0, node_namespaceObject.loadCacheConfig)(loadCachePwd);
43
+ serverBase.notFound((c)=>{
44
+ const monitors = c.get('monitors');
45
+ (0, server_core_namespaceObject.onError)(server_core_namespaceObject.ErrorDigest.ENOTF, '404 not found', monitors, c.req.raw);
46
+ return c.html((0, server_core_namespaceObject.createErrorHtml)(404), 404);
47
+ });
48
+ serverBase.onError(async (err, c)=>{
49
+ const monitors = c.get('monitors');
50
+ (0, server_core_namespaceObject.onError)(server_core_namespaceObject.ErrorDigest.EINTER, err, monitors, c.req.raw);
51
+ if (serverErrorHandler) try {
52
+ const result = await serverErrorHandler(err, c);
53
+ if (result instanceof Response) return result;
54
+ } catch (configError) {
55
+ utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
56
56
  }
57
- } catch (configError) {
58
- import_utils.logger.error(`Error in serverConfig.onError handler: ${configError}`);
59
- }
60
- }
61
- const bffPrefix = ((_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix) || "/api";
62
- const isApiPath = c.req.path.startsWith(bffPrefix);
63
- if (isApiPath) {
64
- return c.json({
65
- message: (err === null || err === void 0 ? void 0 : err.message) || "[BFF] Internal Server Error"
66
- }, (err === null || err === void 0 ? void 0 : err.status) || 500);
67
- } else {
68
- return c.html((0, import_server_core.createErrorHtml)(500), 500);
69
- }
70
- });
71
- const loggerOptions = config.server.logger;
72
- const { middlewares, renderMiddlewares } = options.serverConfig || {};
73
- const plugins = [
74
- ...nodeServer ? [
75
- (0, import_node.injectNodeSeverPlugin)({
76
- nodeServer
77
- })
78
- ] : [],
79
- ...(0, import_server_core.createDefaultPlugins)({
80
- cacheConfig,
81
- staticGenerate: options.staticGenerate,
82
- logger: loggerOptions === false ? false : optLogger || getLogger(loggerOptions)
83
- }),
84
- (0, import_server_core.injectConfigMiddlewarePlugin)(middlewares, renderMiddlewares),
85
- ...options.plugins || [],
86
- (0, import_node.injectResourcePlugin)(),
87
- (0, import_node.injectRscManifestPlugin)(),
88
- (0, import_node.serverStaticPlugin)(),
89
- (0, import_server_core.faviconPlugin)(),
90
- (0, import_server_core.renderPlugin)()
91
- ];
92
- serverBase.addPlugins(plugins);
57
+ const bffPrefix = config.bff?.prefix || '/api';
58
+ const isApiPath = c.req.path.startsWith(bffPrefix);
59
+ if (isApiPath) return c.json({
60
+ message: err?.message || '[BFF] Internal Server Error'
61
+ }, err?.status || 500);
62
+ return c.html((0, server_core_namespaceObject.createErrorHtml)(500), 500);
63
+ });
64
+ const loggerOptions = config.server.logger;
65
+ const { middlewares, renderMiddlewares } = options.serverConfig || {};
66
+ const plugins = [
67
+ ...nodeServer ? [
68
+ (0, node_namespaceObject.injectNodeSeverPlugin)({
69
+ nodeServer
70
+ })
71
+ ] : [],
72
+ ...(0, server_core_namespaceObject.createDefaultPlugins)({
73
+ cacheConfig,
74
+ staticGenerate: options.staticGenerate,
75
+ logger: false === loggerOptions ? false : optLogger || getLogger(loggerOptions)
76
+ }),
77
+ (0, server_core_namespaceObject.injectConfigMiddlewarePlugin)(middlewares, renderMiddlewares),
78
+ ...options.plugins || [],
79
+ (0, node_namespaceObject.injectResourcePlugin)(),
80
+ (0, node_namespaceObject.injectRscManifestPlugin)(),
81
+ (0, node_namespaceObject.serverStaticPlugin)(),
82
+ (0, server_core_namespaceObject.faviconPlugin)(),
83
+ (0, server_core_namespaceObject.renderPlugin)()
84
+ ];
85
+ serverBase.addPlugins(plugins);
93
86
  }
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {
96
- applyPlugins
87
+ exports.applyPlugins = __webpack_exports__.applyPlugins;
88
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
89
+ "applyPlugins"
90
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
91
+ Object.defineProperty(exports, '__esModule', {
92
+ value: true
97
93
  });
package/dist/cjs/index.js CHANGED
@@ -1,59 +1,66 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var src_exports = {};
20
- __export(src_exports, {
21
- applyPlugins: () => import_apply2.applyPlugins,
22
- createProdServer: () => createProdServer,
23
- loadServerPlugins: () => import_node2.loadServerPlugins,
24
- loadServerRuntimeConfig: () => import_node2.loadServerRuntimeConfig
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
+ loadServerRuntimeConfig: ()=>node_namespaceObject.loadServerRuntimeConfig,
28
+ createProdServer: ()=>createProdServer,
29
+ applyPlugins: ()=>external_apply_js_namespaceObject.applyPlugins,
30
+ loadServerPlugins: ()=>node_namespaceObject.loadServerPlugins
25
31
  });
26
- module.exports = __toCommonJS(src_exports);
27
- var import_server_core = require("@modern-js/server-core");
28
- var import_node = require("@modern-js/server-core/node");
29
- var import_apply = require("./apply");
30
- var import_apply2 = require("./apply");
31
- var import_node2 = require("@modern-js/server-core/node");
32
- const createProdServer = async (options) => {
33
- await (0, import_node.loadServerEnv)(options);
34
- const serverBaseOptions = options;
35
- const serverCliConfig = process.env.NODE_ENV === "production" ? (0, import_node.loadServerCliConfig)(options.pwd, options.config) : options.config;
36
- if (serverCliConfig) {
37
- serverBaseOptions.config = serverCliConfig;
38
- }
39
- const serverRuntimeConfig = await (0, import_node.loadServerRuntimeConfig)(options.pwd, options.serverConfigFile, options.serverConfigPath, options.metaName);
40
- if (serverRuntimeConfig) {
41
- serverBaseOptions.serverConfig = serverRuntimeConfig;
42
- serverBaseOptions.plugins = [
43
- ...serverRuntimeConfig.plugins || [],
44
- ...options.plugins || []
45
- ];
46
- }
47
- const server = (0, import_server_core.createServerBase)(serverBaseOptions);
48
- const nodeServer = await (0, import_node.createNodeServer)(server.handle.bind(server));
49
- await (0, import_apply.applyPlugins)(server, options, nodeServer);
50
- await server.init();
51
- return nodeServer;
32
+ const server_core_namespaceObject = require("@modern-js/server-core");
33
+ const node_namespaceObject = require("@modern-js/server-core/node");
34
+ const external_apply_js_namespaceObject = require("./apply.js");
35
+ const createProdServer = async (options)=>{
36
+ await (0, node_namespaceObject.loadServerEnv)(options);
37
+ const serverBaseOptions = options;
38
+ const serverCliConfig = 'production' === process.env.NODE_ENV ? (0, node_namespaceObject.loadServerCliConfig)(options.pwd, options.config) : options.config;
39
+ if (serverCliConfig) serverBaseOptions.config = serverCliConfig;
40
+ const serverRuntimeConfig = await (0, node_namespaceObject.loadServerRuntimeConfig)(options.serverConfigPath);
41
+ if (serverRuntimeConfig) {
42
+ serverBaseOptions.serverConfig = serverRuntimeConfig;
43
+ serverBaseOptions.plugins = [
44
+ ...serverRuntimeConfig.plugins || [],
45
+ ...options.plugins || []
46
+ ];
47
+ }
48
+ const server = (0, server_core_namespaceObject.createServerBase)(serverBaseOptions);
49
+ const nodeServer = await (0, node_namespaceObject.createNodeServer)(server.handle.bind(server));
50
+ await (0, external_apply_js_namespaceObject.applyPlugins)(server, options, nodeServer);
51
+ await server.init();
52
+ return nodeServer;
52
53
  };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- applyPlugins,
56
- createProdServer,
57
- loadServerPlugins,
58
- loadServerRuntimeConfig
54
+ exports.applyPlugins = __webpack_exports__.applyPlugins;
55
+ exports.createProdServer = __webpack_exports__.createProdServer;
56
+ exports.loadServerPlugins = __webpack_exports__.loadServerPlugins;
57
+ exports.loadServerRuntimeConfig = __webpack_exports__.loadServerRuntimeConfig;
58
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
59
+ "applyPlugins",
60
+ "createProdServer",
61
+ "loadServerPlugins",
62
+ "loadServerRuntimeConfig"
63
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
64
+ Object.defineProperty(exports, '__esModule', {
65
+ value: true
59
66
  });
@@ -1,52 +1,56 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var netlify_exports = {};
20
- __export(netlify_exports, {
21
- createNetlifyFunction: () => createNetlifyFunction
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
+ createNetlifyFunction: ()=>createNetlifyFunction
22
28
  });
23
- module.exports = __toCommonJS(netlify_exports);
24
- var import_server_core = require("@modern-js/server-core");
25
- var import_node = require("@modern-js/server-core/node");
26
- var import_apply = require("./apply");
27
- const createNetlifyFunction = async (options) => {
28
- await (0, import_node.loadServerEnv)(options);
29
- const serverBaseOptions = options;
30
- const serverCliConfig = (0, import_node.loadServerCliConfig)(options.pwd, options.config);
31
- if (serverCliConfig) {
32
- options.config = serverCliConfig;
33
- }
34
- const serverRuntimeConfig = await (0, import_node.loadServerRuntimeConfig)(options.pwd, options.serverConfigFile, options.serverConfigPath, options.metaName);
35
- if (serverRuntimeConfig) {
36
- serverBaseOptions.serverConfig = serverRuntimeConfig;
37
- serverBaseOptions.plugins = [
38
- ...serverRuntimeConfig.plugins || [],
39
- ...options.plugins || []
40
- ];
41
- }
42
- const server = (0, import_server_core.createServerBase)(serverBaseOptions);
43
- await (0, import_apply.applyPlugins)(server, options);
44
- await server.init();
45
- return (request, context) => {
46
- return server.handle(request, context);
47
- };
29
+ const server_core_namespaceObject = require("@modern-js/server-core");
30
+ const node_namespaceObject = require("@modern-js/server-core/node");
31
+ const external_apply_js_namespaceObject = require("./apply.js");
32
+ const createNetlifyFunction = async (options)=>{
33
+ await (0, node_namespaceObject.loadServerEnv)(options);
34
+ const serverBaseOptions = options;
35
+ const serverCliConfig = (0, node_namespaceObject.loadServerCliConfig)(options.pwd, options.config);
36
+ if (serverCliConfig) options.config = serverCliConfig;
37
+ const serverRuntimeConfig = await (0, node_namespaceObject.loadServerRuntimeConfig)(options.serverConfigPath);
38
+ if (serverRuntimeConfig) {
39
+ serverBaseOptions.serverConfig = serverRuntimeConfig;
40
+ serverBaseOptions.plugins = [
41
+ ...serverRuntimeConfig.plugins || [],
42
+ ...options.plugins || []
43
+ ];
44
+ }
45
+ const server = (0, server_core_namespaceObject.createServerBase)(serverBaseOptions);
46
+ await (0, external_apply_js_namespaceObject.applyPlugins)(server, options);
47
+ await server.init();
48
+ return (request, context)=>server.handle(request, context);
48
49
  };
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- createNetlifyFunction
50
+ exports.createNetlifyFunction = __webpack_exports__.createNetlifyFunction;
51
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
52
+ "createNetlifyFunction"
53
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
54
+ Object.defineProperty(exports, '__esModule', {
55
+ value: true
52
56
  });
package/dist/cjs/types.js CHANGED
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
@@ -0,0 +1,59 @@
1
+ import { ErrorDigest, createDefaultPlugins, createErrorHtml, faviconPlugin, injectConfigMiddlewarePlugin, onError, renderPlugin } from "@modern-js/server-core";
2
+ import { injectNodeSeverPlugin, injectResourcePlugin, injectRscManifestPlugin, loadCacheConfig, serverStaticPlugin } from "@modern-js/server-core/node";
3
+ import { createLogger, isProd, logger } from "@modern-js/utils";
4
+ function getLogger(_) {
5
+ if (process.env.DEBUG || 'production' === process.env.NODE_ENV) return createLogger({
6
+ level: process.env.MODERN_SERVER_LOG_LEVEL || 'verbose'
7
+ });
8
+ return createLogger();
9
+ }
10
+ async function applyPlugins(serverBase, options, nodeServer) {
11
+ const { pwd, appContext, config, logger: optLogger } = options;
12
+ const serverErrorHandler = options.serverConfig?.onError;
13
+ const loadCachePwd = isProd() ? pwd : appContext.appDirectory || pwd;
14
+ const cacheConfig = await loadCacheConfig(loadCachePwd);
15
+ serverBase.notFound((c)=>{
16
+ const monitors = c.get('monitors');
17
+ onError(ErrorDigest.ENOTF, '404 not found', monitors, c.req.raw);
18
+ return c.html(createErrorHtml(404), 404);
19
+ });
20
+ serverBase.onError(async (err, c)=>{
21
+ const monitors = c.get('monitors');
22
+ onError(ErrorDigest.EINTER, err, monitors, c.req.raw);
23
+ if (serverErrorHandler) try {
24
+ const result = await serverErrorHandler(err, c);
25
+ if (result instanceof Response) return result;
26
+ } catch (configError) {
27
+ logger.error(`Error in serverConfig.onError handler: ${configError}`);
28
+ }
29
+ const bffPrefix = config.bff?.prefix || '/api';
30
+ const isApiPath = c.req.path.startsWith(bffPrefix);
31
+ if (isApiPath) return c.json({
32
+ message: err?.message || '[BFF] Internal Server Error'
33
+ }, err?.status || 500);
34
+ return c.html(createErrorHtml(500), 500);
35
+ });
36
+ const loggerOptions = config.server.logger;
37
+ const { middlewares, renderMiddlewares } = options.serverConfig || {};
38
+ const plugins = [
39
+ ...nodeServer ? [
40
+ injectNodeSeverPlugin({
41
+ nodeServer
42
+ })
43
+ ] : [],
44
+ ...createDefaultPlugins({
45
+ cacheConfig,
46
+ staticGenerate: options.staticGenerate,
47
+ logger: false === loggerOptions ? false : optLogger || getLogger(loggerOptions)
48
+ }),
49
+ injectConfigMiddlewarePlugin(middlewares, renderMiddlewares),
50
+ ...options.plugins || [],
51
+ injectResourcePlugin(),
52
+ injectRscManifestPlugin(),
53
+ serverStaticPlugin(),
54
+ faviconPlugin(),
55
+ renderPlugin()
56
+ ];
57
+ serverBase.addPlugins(plugins);
58
+ }
59
+ export { applyPlugins };
@@ -0,0 +1,23 @@
1
+ import { createServerBase } from "@modern-js/server-core";
2
+ import { createNodeServer, loadServerCliConfig, loadServerEnv, loadServerPlugins, loadServerRuntimeConfig } from "@modern-js/server-core/node";
3
+ import { applyPlugins } from "./apply";
4
+ const createProdServer = async (options)=>{
5
+ await loadServerEnv(options);
6
+ const serverBaseOptions = options;
7
+ const serverCliConfig = 'production' === process.env.NODE_ENV ? loadServerCliConfig(options.pwd, options.config) : options.config;
8
+ if (serverCliConfig) serverBaseOptions.config = serverCliConfig;
9
+ const serverRuntimeConfig = await loadServerRuntimeConfig(options.serverConfigPath);
10
+ if (serverRuntimeConfig) {
11
+ serverBaseOptions.serverConfig = serverRuntimeConfig;
12
+ serverBaseOptions.plugins = [
13
+ ...serverRuntimeConfig.plugins || [],
14
+ ...options.plugins || []
15
+ ];
16
+ }
17
+ const server = createServerBase(serverBaseOptions);
18
+ const nodeServer = await createNodeServer(server.handle.bind(server));
19
+ await applyPlugins(server, options, nodeServer);
20
+ await server.init();
21
+ return nodeServer;
22
+ };
23
+ export { applyPlugins, createProdServer, loadServerPlugins, loadServerRuntimeConfig };
@@ -0,0 +1,22 @@
1
+ import { createServerBase } from "@modern-js/server-core";
2
+ import { loadServerCliConfig, loadServerEnv, loadServerRuntimeConfig } from "@modern-js/server-core/node";
3
+ import { applyPlugins } from "./apply";
4
+ const createNetlifyFunction = async (options)=>{
5
+ await loadServerEnv(options);
6
+ const serverBaseOptions = options;
7
+ const serverCliConfig = loadServerCliConfig(options.pwd, options.config);
8
+ if (serverCliConfig) options.config = serverCliConfig;
9
+ const serverRuntimeConfig = await loadServerRuntimeConfig(options.serverConfigPath);
10
+ if (serverRuntimeConfig) {
11
+ serverBaseOptions.serverConfig = serverRuntimeConfig;
12
+ serverBaseOptions.plugins = [
13
+ ...serverRuntimeConfig.plugins || [],
14
+ ...options.plugins || []
15
+ ];
16
+ }
17
+ const server = createServerBase(serverBaseOptions);
18
+ await applyPlugins(server, options);
19
+ await server.init();
20
+ return (request, context)=>server.handle(request, context);
21
+ };
22
+ export { createNetlifyFunction };
@@ -0,0 +1,59 @@
1
+ import { ErrorDigest, createDefaultPlugins, createErrorHtml, faviconPlugin, injectConfigMiddlewarePlugin, onError, renderPlugin } from "@modern-js/server-core";
2
+ import { injectNodeSeverPlugin, injectResourcePlugin, injectRscManifestPlugin, loadCacheConfig, serverStaticPlugin } from "@modern-js/server-core/node";
3
+ import { createLogger, isProd, logger } from "@modern-js/utils";
4
+ function getLogger(_) {
5
+ if (process.env.DEBUG || 'production' === process.env.NODE_ENV) return createLogger({
6
+ level: process.env.MODERN_SERVER_LOG_LEVEL || 'verbose'
7
+ });
8
+ return createLogger();
9
+ }
10
+ async function applyPlugins(serverBase, options, nodeServer) {
11
+ const { pwd, appContext, config, logger: optLogger } = options;
12
+ const serverErrorHandler = options.serverConfig?.onError;
13
+ const loadCachePwd = isProd() ? pwd : appContext.appDirectory || pwd;
14
+ const cacheConfig = await loadCacheConfig(loadCachePwd);
15
+ serverBase.notFound((c)=>{
16
+ const monitors = c.get('monitors');
17
+ onError(ErrorDigest.ENOTF, '404 not found', monitors, c.req.raw);
18
+ return c.html(createErrorHtml(404), 404);
19
+ });
20
+ serverBase.onError(async (err, c)=>{
21
+ const monitors = c.get('monitors');
22
+ onError(ErrorDigest.EINTER, err, monitors, c.req.raw);
23
+ if (serverErrorHandler) try {
24
+ const result = await serverErrorHandler(err, c);
25
+ if (result instanceof Response) return result;
26
+ } catch (configError) {
27
+ logger.error(`Error in serverConfig.onError handler: ${configError}`);
28
+ }
29
+ const bffPrefix = config.bff?.prefix || '/api';
30
+ const isApiPath = c.req.path.startsWith(bffPrefix);
31
+ if (isApiPath) return c.json({
32
+ message: err?.message || '[BFF] Internal Server Error'
33
+ }, err?.status || 500);
34
+ return c.html(createErrorHtml(500), 500);
35
+ });
36
+ const loggerOptions = config.server.logger;
37
+ const { middlewares, renderMiddlewares } = options.serverConfig || {};
38
+ const plugins = [
39
+ ...nodeServer ? [
40
+ injectNodeSeverPlugin({
41
+ nodeServer
42
+ })
43
+ ] : [],
44
+ ...createDefaultPlugins({
45
+ cacheConfig,
46
+ staticGenerate: options.staticGenerate,
47
+ logger: false === loggerOptions ? false : optLogger || getLogger(loggerOptions)
48
+ }),
49
+ injectConfigMiddlewarePlugin(middlewares, renderMiddlewares),
50
+ ...options.plugins || [],
51
+ injectResourcePlugin(),
52
+ injectRscManifestPlugin(),
53
+ serverStaticPlugin(),
54
+ faviconPlugin(),
55
+ renderPlugin()
56
+ ];
57
+ serverBase.addPlugins(plugins);
58
+ }
59
+ export { applyPlugins };
@@ -0,0 +1,23 @@
1
+ import { createServerBase } from "@modern-js/server-core";
2
+ import { createNodeServer, loadServerCliConfig, loadServerEnv, loadServerPlugins, loadServerRuntimeConfig } from "@modern-js/server-core/node";
3
+ import { applyPlugins } from "./apply.mjs";
4
+ const createProdServer = async (options)=>{
5
+ await loadServerEnv(options);
6
+ const serverBaseOptions = options;
7
+ const serverCliConfig = 'production' === process.env.NODE_ENV ? loadServerCliConfig(options.pwd, options.config) : options.config;
8
+ if (serverCliConfig) serverBaseOptions.config = serverCliConfig;
9
+ const serverRuntimeConfig = await loadServerRuntimeConfig(options.serverConfigPath);
10
+ if (serverRuntimeConfig) {
11
+ serverBaseOptions.serverConfig = serverRuntimeConfig;
12
+ serverBaseOptions.plugins = [
13
+ ...serverRuntimeConfig.plugins || [],
14
+ ...options.plugins || []
15
+ ];
16
+ }
17
+ const server = createServerBase(serverBaseOptions);
18
+ const nodeServer = await createNodeServer(server.handle.bind(server));
19
+ await applyPlugins(server, options, nodeServer);
20
+ await server.init();
21
+ return nodeServer;
22
+ };
23
+ export { applyPlugins, createProdServer, loadServerPlugins, loadServerRuntimeConfig };
@@ -0,0 +1,22 @@
1
+ import { createServerBase } from "@modern-js/server-core";
2
+ import { loadServerCliConfig, loadServerEnv, loadServerRuntimeConfig } from "@modern-js/server-core/node";
3
+ import { applyPlugins } from "./apply.mjs";
4
+ const createNetlifyFunction = async (options)=>{
5
+ await loadServerEnv(options);
6
+ const serverBaseOptions = options;
7
+ const serverCliConfig = loadServerCliConfig(options.pwd, options.config);
8
+ if (serverCliConfig) options.config = serverCliConfig;
9
+ const serverRuntimeConfig = await loadServerRuntimeConfig(options.serverConfigPath);
10
+ if (serverRuntimeConfig) {
11
+ serverBaseOptions.serverConfig = serverRuntimeConfig;
12
+ serverBaseOptions.plugins = [
13
+ ...serverRuntimeConfig.plugins || [],
14
+ ...options.plugins || []
15
+ ];
16
+ }
17
+ const server = createServerBase(serverBaseOptions);
18
+ await applyPlugins(server, options);
19
+ await server.init();
20
+ return (request, context)=>server.handle(request, context);
21
+ };
22
+ export { createNetlifyFunction };
@@ -4,9 +4,9 @@
4
4
  import type { ProdServerOptions } from './types';
5
5
  export { applyPlugins, type ApplyPlugins } from './apply';
6
6
  export { loadServerPlugins, loadServerRuntimeConfig, } from '@modern-js/server-core/node';
7
- export type { ServerPluginLegacy, ServerPlugin } from '@modern-js/server-core';
7
+ export type { ServerPlugin } from '@modern-js/server-core';
8
8
  export type { ProdServerOptions, BaseEnv } from './types';
9
- export declare const createProdServer: (options: ProdServerOptions) => Promise<(import("http2").Http2SecureServer | import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>) & {
10
- getRequestListener: () => (req: import("@modern-js/types").NodeRequest, res: import("@modern-js/types").NodeResponse) => Promise<void>;
9
+ export declare const createProdServer: (options: ProdServerOptions) => Promise<(import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("http2").Http2SecureServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse, typeof import("http2").Http2ServerRequest, typeof import("http2").Http2ServerResponse>) & {
10
+ getRequestListener: () => (req: import("@modern-js/types/server").NodeRequest, res: import("@modern-js/types/server").NodeResponse) => Promise<void>;
11
11
  getRequestHandler: () => import("@modern-js/server-core/dist/types/types").RequestHandler;
12
12
  }>;
@@ -1,11 +1,9 @@
1
- import type { CreateDefaultPluginsOptions, ServerBaseOptions, ServerPlugin, ServerPluginLegacy } from '@modern-js/server-core';
1
+ import type { CreateDefaultPluginsOptions, ServerBaseOptions, ServerPlugin } from '@modern-js/server-core';
2
2
  import type { Reporter } from '@modern-js/types';
3
3
  import type { Logger } from '@modern-js/utils';
4
4
  interface ProdServerExtraOptions {
5
- /** compat modern.server-runtime.config.ts */
6
- serverConfigFile?: string;
7
5
  serverConfigPath: string;
8
- plugins?: (ServerPlugin | ServerPluginLegacy)[];
6
+ plugins?: ServerPlugin[];
9
7
  }
10
8
  export type ProdServerOptions = ServerBaseOptions & ProdServerExtraOptions & CreateDefaultPluginsOptions;
11
9
  export type BaseEnv = {
package/package.json CHANGED
@@ -15,20 +15,26 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.69.4",
18
+ "version": "3.0.0-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
22
- "module": "./dist/es/index.js",
22
+ "module": "./dist/esm-node/index.mjs",
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/types/index.d.ts",
26
- "jsnext:source": "./src/index.ts",
26
+ "node": {
27
+ "import": "./dist/esm-node/index.mjs",
28
+ "require": "./dist/cjs/index.js"
29
+ },
27
30
  "default": "./dist/cjs/index.js"
28
31
  },
29
32
  "./netlify": {
30
33
  "types": "./dist/types/netlify.d.ts",
31
- "jsnext:source": "./src/netlify.ts",
34
+ "node": {
35
+ "import": "./dist/esm-node/netlify.mjs",
36
+ "require": "./dist/cjs/netlify.js"
37
+ },
32
38
  "default": "./dist/cjs/netlify.js"
33
39
  }
34
40
  },
@@ -36,39 +42,39 @@
36
42
  "*": {
37
43
  ".": [
38
44
  "./dist/types/index.d.ts"
45
+ ],
46
+ "netlify": [
47
+ "./dist/types/netlify.d.ts"
39
48
  ]
40
49
  }
41
50
  },
42
51
  "dependencies": {
43
52
  "@swc/helpers": "^0.5.17",
44
- "@modern-js/runtime-utils": "2.69.4",
45
- "@modern-js/server-core": "2.69.4",
46
- "@modern-js/utils": "2.69.4"
53
+ "@modern-js/runtime-utils": "3.0.0-alpha.0",
54
+ "@modern-js/server-core": "3.0.0-alpha.0",
55
+ "@modern-js/utils": "3.0.0-alpha.0"
47
56
  },
48
57
  "devDependencies": {
49
- "@types/jest": "^29",
50
- "@types/merge-deep": "^3.0.0",
51
- "@types/node": "~16.11.7",
52
- "jest": "^29",
58
+ "@types/merge-deep": "^3.0.3",
59
+ "@types/node": "^20",
53
60
  "lint-staged": "~13.3.0",
54
- "tsx": "^3.12.7",
61
+ "@rslib/core": "0.18.5",
55
62
  "typescript": "~5.0.4",
56
- "@modern-js/types": "2.69.4",
57
- "@scripts/build": "2.66.0",
58
- "@scripts/jest-config": "2.66.0"
63
+ "@modern-js/types": "3.0.0-alpha.0",
64
+ "@scripts/rstest-config": "2.66.0",
65
+ "@modern-js/rslib": "2.68.10"
59
66
  },
60
67
  "sideEffects": [],
61
68
  "engines": {
62
- "node": ">=16.2.0"
69
+ "node": ">=20"
63
70
  },
64
71
  "publishConfig": {
65
72
  "access": "public",
66
73
  "registry": "https://registry.npmjs.org/"
67
74
  },
68
75
  "scripts": {
69
- "new": "modern-lib new",
70
- "build": "modern-lib build",
71
- "dev": "modern-lib build --watch",
72
- "test": "jest"
76
+ "build": "rslib build",
77
+ "dev": "rslib build --watch",
78
+ "test": "rstest --passWithNoTests"
73
79
  }
74
80
  }
@@ -0,0 +1,4 @@
1
+ import { rslibConfig } from '@modern-js/rslib';
2
+ import { defineConfig } from '@rslib/core';
3
+
4
+ export default defineConfig(rslibConfig);
@@ -0,0 +1,7 @@
1
+ import { withTestPreset } from '@scripts/rstest-config';
2
+
3
+ export default withTestPreset({
4
+ root: __dirname,
5
+ testEnvironment: 'node',
6
+ globals: true,
7
+ });
package/dist/esm/apply.js DELETED
@@ -1,140 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import { ErrorDigest, createDefaultPlugins, createErrorHtml, faviconPlugin, injectConfigMiddlewarePlugin, onError, renderPlugin } from "@modern-js/server-core";
6
- import { injectNodeSeverPlugin, injectResourcePlugin, injectRscManifestPlugin, loadCacheConfig, serverStaticPlugin } from "@modern-js/server-core/node";
7
- import { createLogger, isProd, logger } from "@modern-js/utils";
8
- function getLogger(_) {
9
- if (process.env.DEBUG || process.env.NODE_ENV === "production") {
10
- return createLogger({
11
- level: process.env.MODERN_SERVER_LOG_LEVEL || "verbose"
12
- });
13
- } else {
14
- return createLogger();
15
- }
16
- }
17
- function applyPlugins(serverBase, options, nodeServer) {
18
- return _applyPlugins.apply(this, arguments);
19
- }
20
- function _applyPlugins() {
21
- _applyPlugins = _async_to_generator(function(serverBase, options, nodeServer) {
22
- var _options_serverConfig, pwd, appContext, config, optLogger, serverErrorHandler, loadCachePwd, cacheConfig, loggerOptions, _ref, middlewares, renderMiddlewares, plugins;
23
- return _ts_generator(this, function(_state) {
24
- switch (_state.label) {
25
- case 0:
26
- pwd = options.pwd, appContext = options.appContext, config = options.config, optLogger = options.logger;
27
- serverErrorHandler = (_options_serverConfig = options.serverConfig) === null || _options_serverConfig === void 0 ? void 0 : _options_serverConfig.onError;
28
- loadCachePwd = isProd() ? pwd : appContext.appDirectory || pwd;
29
- return [
30
- 4,
31
- loadCacheConfig(loadCachePwd)
32
- ];
33
- case 1:
34
- cacheConfig = _state.sent();
35
- serverBase.notFound(function(c) {
36
- var monitors = c.get("monitors");
37
- onError(ErrorDigest.ENOTF, "404 not found", monitors, c.req.raw);
38
- return c.html(createErrorHtml(404), 404);
39
- });
40
- serverBase.onError(function() {
41
- var _ref2 = _async_to_generator(function(err, c) {
42
- var _config_bff, monitors, result, configError, bffPrefix, isApiPath;
43
- return _ts_generator(this, function(_state2) {
44
- switch (_state2.label) {
45
- case 0:
46
- monitors = c.get("monitors");
47
- onError(ErrorDigest.EINTER, err, monitors, c.req.raw);
48
- if (!serverErrorHandler)
49
- return [
50
- 3,
51
- 4
52
- ];
53
- _state2.label = 1;
54
- case 1:
55
- _state2.trys.push([
56
- 1,
57
- 3,
58
- ,
59
- 4
60
- ]);
61
- return [
62
- 4,
63
- serverErrorHandler(err, c)
64
- ];
65
- case 2:
66
- result = _state2.sent();
67
- if (_instanceof(result, Response)) {
68
- return [
69
- 2,
70
- result
71
- ];
72
- }
73
- return [
74
- 3,
75
- 4
76
- ];
77
- case 3:
78
- configError = _state2.sent();
79
- logger.error("Error in serverConfig.onError handler: ".concat(configError));
80
- return [
81
- 3,
82
- 4
83
- ];
84
- case 4:
85
- bffPrefix = ((_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix) || "/api";
86
- isApiPath = c.req.path.startsWith(bffPrefix);
87
- if (isApiPath) {
88
- return [
89
- 2,
90
- c.json({
91
- message: (err === null || err === void 0 ? void 0 : err.message) || "[BFF] Internal Server Error"
92
- }, (err === null || err === void 0 ? void 0 : err.status) || 500)
93
- ];
94
- } else {
95
- return [
96
- 2,
97
- c.html(createErrorHtml(500), 500)
98
- ];
99
- }
100
- return [
101
- 2
102
- ];
103
- }
104
- });
105
- });
106
- return function(err, c) {
107
- return _ref2.apply(this, arguments);
108
- };
109
- }());
110
- loggerOptions = config.server.logger;
111
- _ref = options.serverConfig || {}, middlewares = _ref.middlewares, renderMiddlewares = _ref.renderMiddlewares;
112
- plugins = _to_consumable_array(nodeServer ? [
113
- injectNodeSeverPlugin({
114
- nodeServer
115
- })
116
- ] : []).concat(_to_consumable_array(createDefaultPlugins({
117
- cacheConfig,
118
- staticGenerate: options.staticGenerate,
119
- logger: loggerOptions === false ? false : optLogger || getLogger(loggerOptions)
120
- })), [
121
- injectConfigMiddlewarePlugin(middlewares, renderMiddlewares)
122
- ], _to_consumable_array(options.plugins || []), [
123
- injectResourcePlugin(),
124
- injectRscManifestPlugin(),
125
- serverStaticPlugin(),
126
- faviconPlugin(),
127
- renderPlugin()
128
- ]);
129
- serverBase.addPlugins(plugins);
130
- return [
131
- 2
132
- ];
133
- }
134
- });
135
- });
136
- return _applyPlugins.apply(this, arguments);
137
- }
138
- export {
139
- applyPlugins
140
- };
package/dist/esm/index.js DELETED
@@ -1,71 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { createServerBase } from "@modern-js/server-core";
5
- import { createNodeServer, loadServerCliConfig, loadServerEnv, loadServerRuntimeConfig } from "@modern-js/server-core/node";
6
- import { applyPlugins } from "./apply";
7
- import { applyPlugins as applyPlugins2 } from "./apply";
8
- import { loadServerPlugins, loadServerRuntimeConfig as loadServerRuntimeConfig2 } from "@modern-js/server-core/node";
9
- var createProdServer = function() {
10
- var _ref = _async_to_generator(function(options) {
11
- var serverBaseOptions, serverCliConfig, serverRuntimeConfig, server, nodeServer;
12
- return _ts_generator(this, function(_state) {
13
- switch (_state.label) {
14
- case 0:
15
- return [
16
- 4,
17
- loadServerEnv(options)
18
- ];
19
- case 1:
20
- _state.sent();
21
- serverBaseOptions = options;
22
- serverCliConfig = process.env.NODE_ENV === "production" ? loadServerCliConfig(options.pwd, options.config) : options.config;
23
- if (serverCliConfig) {
24
- serverBaseOptions.config = serverCliConfig;
25
- }
26
- return [
27
- 4,
28
- loadServerRuntimeConfig(options.pwd, options.serverConfigFile, options.serverConfigPath, options.metaName)
29
- ];
30
- case 2:
31
- serverRuntimeConfig = _state.sent();
32
- if (serverRuntimeConfig) {
33
- serverBaseOptions.serverConfig = serverRuntimeConfig;
34
- serverBaseOptions.plugins = _to_consumable_array(serverRuntimeConfig.plugins || []).concat(_to_consumable_array(options.plugins || []));
35
- }
36
- server = createServerBase(serverBaseOptions);
37
- return [
38
- 4,
39
- createNodeServer(server.handle.bind(server))
40
- ];
41
- case 3:
42
- nodeServer = _state.sent();
43
- return [
44
- 4,
45
- applyPlugins(server, options, nodeServer)
46
- ];
47
- case 4:
48
- _state.sent();
49
- return [
50
- 4,
51
- server.init()
52
- ];
53
- case 5:
54
- _state.sent();
55
- return [
56
- 2,
57
- nodeServer
58
- ];
59
- }
60
- });
61
- });
62
- return function createProdServer2(options) {
63
- return _ref.apply(this, arguments);
64
- };
65
- }();
66
- export {
67
- applyPlugins2 as applyPlugins,
68
- createProdServer,
69
- loadServerPlugins,
70
- loadServerRuntimeConfig2 as loadServerRuntimeConfig
71
- };
@@ -1,62 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { createServerBase } from "@modern-js/server-core";
5
- import { loadServerCliConfig, loadServerEnv, loadServerRuntimeConfig } from "@modern-js/server-core/node";
6
- import { applyPlugins } from "./apply";
7
- var createNetlifyFunction = function() {
8
- var _ref = _async_to_generator(function(options) {
9
- var serverBaseOptions, serverCliConfig, serverRuntimeConfig, server;
10
- return _ts_generator(this, function(_state) {
11
- switch (_state.label) {
12
- case 0:
13
- return [
14
- 4,
15
- loadServerEnv(options)
16
- ];
17
- case 1:
18
- _state.sent();
19
- serverBaseOptions = options;
20
- serverCliConfig = loadServerCliConfig(options.pwd, options.config);
21
- if (serverCliConfig) {
22
- options.config = serverCliConfig;
23
- }
24
- return [
25
- 4,
26
- loadServerRuntimeConfig(options.pwd, options.serverConfigFile, options.serverConfigPath, options.metaName)
27
- ];
28
- case 2:
29
- serverRuntimeConfig = _state.sent();
30
- if (serverRuntimeConfig) {
31
- serverBaseOptions.serverConfig = serverRuntimeConfig;
32
- serverBaseOptions.plugins = _to_consumable_array(serverRuntimeConfig.plugins || []).concat(_to_consumable_array(options.plugins || []));
33
- }
34
- server = createServerBase(serverBaseOptions);
35
- return [
36
- 4,
37
- applyPlugins(server, options)
38
- ];
39
- case 3:
40
- _state.sent();
41
- return [
42
- 4,
43
- server.init()
44
- ];
45
- case 4:
46
- _state.sent();
47
- return [
48
- 2,
49
- function(request, context) {
50
- return server.handle(request, context);
51
- }
52
- ];
53
- }
54
- });
55
- });
56
- return function createNetlifyFunction2(options) {
57
- return _ref.apply(this, arguments);
58
- };
59
- }();
60
- export {
61
- createNetlifyFunction
62
- };
@@ -1,73 +0,0 @@
1
- import { ErrorDigest, createDefaultPlugins, createErrorHtml, faviconPlugin, injectConfigMiddlewarePlugin, onError, renderPlugin } from "@modern-js/server-core";
2
- import { injectNodeSeverPlugin, injectResourcePlugin, injectRscManifestPlugin, loadCacheConfig, serverStaticPlugin } from "@modern-js/server-core/node";
3
- import { createLogger, isProd, logger } from "@modern-js/utils";
4
- function getLogger(_) {
5
- if (process.env.DEBUG || process.env.NODE_ENV === "production") {
6
- return createLogger({
7
- level: process.env.MODERN_SERVER_LOG_LEVEL || "verbose"
8
- });
9
- } else {
10
- return createLogger();
11
- }
12
- }
13
- async function applyPlugins(serverBase, options, nodeServer) {
14
- var _options_serverConfig;
15
- const { pwd, appContext, config, logger: optLogger } = options;
16
- const serverErrorHandler = (_options_serverConfig = options.serverConfig) === null || _options_serverConfig === void 0 ? void 0 : _options_serverConfig.onError;
17
- const loadCachePwd = isProd() ? pwd : appContext.appDirectory || pwd;
18
- const cacheConfig = await loadCacheConfig(loadCachePwd);
19
- serverBase.notFound((c) => {
20
- const monitors = c.get("monitors");
21
- onError(ErrorDigest.ENOTF, "404 not found", monitors, c.req.raw);
22
- return c.html(createErrorHtml(404), 404);
23
- });
24
- serverBase.onError(async (err, c) => {
25
- var _config_bff;
26
- const monitors = c.get("monitors");
27
- onError(ErrorDigest.EINTER, err, monitors, c.req.raw);
28
- if (serverErrorHandler) {
29
- try {
30
- const result = await serverErrorHandler(err, c);
31
- if (result instanceof Response) {
32
- return result;
33
- }
34
- } catch (configError) {
35
- logger.error(`Error in serverConfig.onError handler: ${configError}`);
36
- }
37
- }
38
- const bffPrefix = ((_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix) || "/api";
39
- const isApiPath = c.req.path.startsWith(bffPrefix);
40
- if (isApiPath) {
41
- return c.json({
42
- message: (err === null || err === void 0 ? void 0 : err.message) || "[BFF] Internal Server Error"
43
- }, (err === null || err === void 0 ? void 0 : err.status) || 500);
44
- } else {
45
- return c.html(createErrorHtml(500), 500);
46
- }
47
- });
48
- const loggerOptions = config.server.logger;
49
- const { middlewares, renderMiddlewares } = options.serverConfig || {};
50
- const plugins = [
51
- ...nodeServer ? [
52
- injectNodeSeverPlugin({
53
- nodeServer
54
- })
55
- ] : [],
56
- ...createDefaultPlugins({
57
- cacheConfig,
58
- staticGenerate: options.staticGenerate,
59
- logger: loggerOptions === false ? false : optLogger || getLogger(loggerOptions)
60
- }),
61
- injectConfigMiddlewarePlugin(middlewares, renderMiddlewares),
62
- ...options.plugins || [],
63
- injectResourcePlugin(),
64
- injectRscManifestPlugin(),
65
- serverStaticPlugin(),
66
- faviconPlugin(),
67
- renderPlugin()
68
- ];
69
- serverBase.addPlugins(plugins);
70
- }
71
- export {
72
- applyPlugins
73
- };
@@ -1,32 +0,0 @@
1
- import { createServerBase } from "@modern-js/server-core";
2
- import { createNodeServer, loadServerCliConfig, loadServerEnv, loadServerRuntimeConfig } from "@modern-js/server-core/node";
3
- import { applyPlugins } from "./apply";
4
- import { applyPlugins as applyPlugins2 } from "./apply";
5
- import { loadServerPlugins, loadServerRuntimeConfig as loadServerRuntimeConfig2 } from "@modern-js/server-core/node";
6
- const createProdServer = async (options) => {
7
- await loadServerEnv(options);
8
- const serverBaseOptions = options;
9
- const serverCliConfig = process.env.NODE_ENV === "production" ? loadServerCliConfig(options.pwd, options.config) : options.config;
10
- if (serverCliConfig) {
11
- serverBaseOptions.config = serverCliConfig;
12
- }
13
- const serverRuntimeConfig = await loadServerRuntimeConfig(options.pwd, options.serverConfigFile, options.serverConfigPath, options.metaName);
14
- if (serverRuntimeConfig) {
15
- serverBaseOptions.serverConfig = serverRuntimeConfig;
16
- serverBaseOptions.plugins = [
17
- ...serverRuntimeConfig.plugins || [],
18
- ...options.plugins || []
19
- ];
20
- }
21
- const server = createServerBase(serverBaseOptions);
22
- const nodeServer = await createNodeServer(server.handle.bind(server));
23
- await applyPlugins(server, options, nodeServer);
24
- await server.init();
25
- return nodeServer;
26
- };
27
- export {
28
- applyPlugins2 as applyPlugins,
29
- createProdServer,
30
- loadServerPlugins,
31
- loadServerRuntimeConfig2 as loadServerRuntimeConfig
32
- };
@@ -1,28 +0,0 @@
1
- import { createServerBase } from "@modern-js/server-core";
2
- import { loadServerCliConfig, loadServerEnv, loadServerRuntimeConfig } from "@modern-js/server-core/node";
3
- import { applyPlugins } from "./apply";
4
- const createNetlifyFunction = async (options) => {
5
- await loadServerEnv(options);
6
- const serverBaseOptions = options;
7
- const serverCliConfig = loadServerCliConfig(options.pwd, options.config);
8
- if (serverCliConfig) {
9
- options.config = serverCliConfig;
10
- }
11
- const serverRuntimeConfig = await loadServerRuntimeConfig(options.pwd, options.serverConfigFile, options.serverConfigPath, options.metaName);
12
- if (serverRuntimeConfig) {
13
- serverBaseOptions.serverConfig = serverRuntimeConfig;
14
- serverBaseOptions.plugins = [
15
- ...serverRuntimeConfig.plugins || [],
16
- ...options.plugins || []
17
- ];
18
- }
19
- const server = createServerBase(serverBaseOptions);
20
- await applyPlugins(server, options);
21
- await server.init();
22
- return (request, context) => {
23
- return server.handle(request, context);
24
- };
25
- };
26
- export {
27
- createNetlifyFunction
28
- };
File without changes
File without changes