@modern-js/server-core 2.56.2 → 2.57.1-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/adapters/node/helper/loadConfig.js +2 -2
- package/dist/cjs/adapters/node/plugins/resource.js +4 -1
- package/dist/cjs/{plugins/customServer/loader.js → helper.js} +6 -5
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/plugins/customServer/base.js +3 -0
- package/dist/cjs/plugins/customServer/index.js +2 -5
- package/dist/cjs/plugins/default.js +42 -0
- package/dist/cjs/plugins/index.js +6 -6
- package/dist/cjs/plugins/monitors.js +4 -3
- package/dist/cjs/plugins/render/index.js +10 -34
- package/dist/cjs/plugins/render/inject.js +75 -0
- package/dist/cjs/plugins/render/render.js +33 -2
- package/dist/esm/adapters/node/helper/loadConfig.js +2 -2
- package/dist/esm/adapters/node/plugins/resource.js +13 -3
- package/dist/esm/{plugins/customServer/loader.js → helper.js} +3 -2
- package/dist/esm/index.js +2 -0
- package/dist/esm/plugins/customServer/base.js +3 -0
- package/dist/esm/plugins/customServer/index.js +1 -3
- package/dist/esm/plugins/default.js +19 -0
- package/dist/esm/plugins/index.js +5 -5
- package/dist/esm/plugins/monitors.js +3 -3
- package/dist/esm/plugins/render/index.js +27 -70
- package/dist/esm/plugins/render/inject.js +85 -0
- package/dist/esm/plugins/render/render.js +50 -16
- package/dist/esm-node/adapters/node/helper/loadConfig.js +2 -2
- package/dist/esm-node/adapters/node/plugins/resource.js +5 -2
- package/dist/esm-node/{plugins/customServer/loader.js → helper.js} +3 -2
- package/dist/esm-node/index.js +2 -0
- package/dist/esm-node/plugins/customServer/base.js +3 -0
- package/dist/esm-node/plugins/customServer/index.js +1 -3
- package/dist/esm-node/plugins/default.js +18 -0
- package/dist/esm-node/plugins/index.js +5 -5
- package/dist/esm-node/plugins/monitors.js +4 -3
- package/dist/esm-node/plugins/render/index.js +7 -32
- package/dist/esm-node/plugins/render/inject.js +50 -0
- package/dist/esm-node/plugins/render/render.js +23 -2
- package/dist/types/{plugins/customServer/loader.d.ts → helper.d.ts} +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/customServer/index.d.ts +0 -1
- package/dist/types/plugins/default.d.ts +7 -0
- package/dist/types/plugins/index.d.ts +3 -3
- package/dist/types/plugins/monitors.d.ts +2 -2
- package/dist/types/plugins/render/index.d.ts +3 -16
- package/dist/types/plugins/render/inject.d.ts +7 -0
- package/dist/types/types/config/output.d.ts +0 -1
- package/dist/types/types/config/server.d.ts +4 -0
- package/dist/types/types/plugin.d.ts +10 -0
- package/dist/types/types/server.d.ts +1 -0
- package/package.json +7 -7
|
@@ -61,8 +61,8 @@ function loadServerRuntimeConfig(pwd, oldServerFile = import_utils.DEFAULT_SERVE
|
|
|
61
61
|
return oldServerConfig;
|
|
62
62
|
}
|
|
63
63
|
function loadServerCliConfig(pwd, defaultConfig = {}) {
|
|
64
|
-
var _defaultConfig_output;
|
|
65
|
-
const cliConfigPath = (0, import_utils.ensureAbsolutePath)(pwd, import_path.default.join(((_defaultConfig_output = defaultConfig.output) === null || _defaultConfig_output === void 0 ? void 0 : _defaultConfig_output.
|
|
64
|
+
var _defaultConfig_output_distPath, _defaultConfig_output;
|
|
65
|
+
const cliConfigPath = (0, import_utils.ensureAbsolutePath)(pwd, import_path.default.join(((_defaultConfig_output = defaultConfig.output) === null || _defaultConfig_output === void 0 ? void 0 : (_defaultConfig_output_distPath = _defaultConfig_output.distPath) === null || _defaultConfig_output_distPath === void 0 ? void 0 : _defaultConfig_output_distPath.root) || "dist", import_utils.OUTPUT_CONFIG_FILE));
|
|
66
66
|
let cliConfig = {
|
|
67
67
|
output: {},
|
|
68
68
|
source: {},
|
|
@@ -97,11 +97,14 @@ async function getServerManifest(pwd, routes, logger) {
|
|
|
97
97
|
const loadableStats = await Promise.resolve().then(() => __toESM(require(loadableUri))).catch((_) => ({}));
|
|
98
98
|
const routesManifestUri = import_path.default.join(pwd, import_utils.ROUTE_MANIFEST_FILE);
|
|
99
99
|
const routeManifest = await Promise.resolve().then(() => __toESM(require(routesManifestUri))).catch((_) => ({}));
|
|
100
|
+
const nestedRoutesJsonPath = import_path.default.join(pwd, import_utils.NESTED_ROUTE_SPEC_FILE);
|
|
101
|
+
const nestedRoutesJson = await Promise.resolve().then(() => __toESM(require(nestedRoutesJsonPath))).catch((_) => ({}));
|
|
100
102
|
return {
|
|
101
103
|
loaderBundles,
|
|
102
104
|
renderBundles,
|
|
103
105
|
loadableStats,
|
|
104
|
-
routeManifest
|
|
106
|
+
routeManifest,
|
|
107
|
+
nestedRoutesJson
|
|
105
108
|
};
|
|
106
109
|
}
|
|
107
110
|
function injectServerManifest(pwd, routes) {
|
|
@@ -16,18 +16,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var helper_exports = {};
|
|
20
|
+
__export(helper_exports, {
|
|
21
21
|
getLoaderCtx: () => getLoaderCtx
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(helper_exports);
|
|
24
|
+
const LOADER_CONTEXT = "loaderContext";
|
|
24
25
|
function getLoaderCtx(c) {
|
|
25
|
-
const loaderContext = c.get(
|
|
26
|
+
const loaderContext = c.get(LOADER_CONTEXT);
|
|
26
27
|
if (loaderContext) {
|
|
27
28
|
return loaderContext;
|
|
28
29
|
} else {
|
|
29
30
|
const loaderContext2 = /* @__PURE__ */ new Map();
|
|
30
|
-
c.set(
|
|
31
|
+
c.set(LOADER_CONTEXT, loaderContext2);
|
|
31
32
|
return loaderContext2;
|
|
32
33
|
}
|
|
33
34
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(src_exports, {
|
|
|
24
24
|
PluginManager: () => import_pluginManager.PluginManager,
|
|
25
25
|
createErrorHtml: () => import_utils.createErrorHtml,
|
|
26
26
|
createServerBase: () => import_serverBase.createServerBase,
|
|
27
|
+
getLoaderCtx: () => import_helper.getLoaderCtx,
|
|
27
28
|
onError: () => import_utils.onError
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -31,6 +32,7 @@ var import_utils = require("./utils");
|
|
|
31
32
|
var import_constants = require("./constants");
|
|
32
33
|
var import_serverBase = require("./serverBase");
|
|
33
34
|
var import_pluginManager = require("./pluginManager");
|
|
35
|
+
var import_helper = require("./helper");
|
|
34
36
|
__reExport(src_exports, require("./plugins"), module.exports);
|
|
35
37
|
__reExport(src_exports, require("./types/plugin"), module.exports);
|
|
36
38
|
__reExport(src_exports, require("./types/render"), module.exports);
|
|
@@ -44,6 +46,7 @@ __reExport(src_exports, require("./types/requestHandler"), module.exports);
|
|
|
44
46
|
PluginManager,
|
|
45
47
|
createErrorHtml,
|
|
46
48
|
createServerBase,
|
|
49
|
+
getLoaderCtx,
|
|
47
50
|
onError,
|
|
48
51
|
...require("./plugins"),
|
|
49
52
|
...require("./types/plugin"),
|
|
@@ -143,6 +143,9 @@ class BaseHookResponse {
|
|
|
143
143
|
(0, import_class_private_field_get._)(this, _c1).status(code);
|
|
144
144
|
(0, import_class_private_field_get._)(this, _resArgs) && ((0, import_class_private_field_get._)(this, _resArgs).status = code);
|
|
145
145
|
}
|
|
146
|
+
getStatus() {
|
|
147
|
+
return (0, import_class_private_field_get._)(this, _c1).res.status;
|
|
148
|
+
}
|
|
146
149
|
get cookies() {
|
|
147
150
|
const setCookie = (key, value) => {
|
|
148
151
|
(0, import_class_private_field_get._)(this, _c1).header("set-cookie", `${key}=${value}`, {
|
|
@@ -29,17 +29,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var customServer_exports = {};
|
|
30
30
|
__export(customServer_exports, {
|
|
31
31
|
CustomServer: () => CustomServer,
|
|
32
|
-
getLoaderCtx: () => import_loader2.getLoaderCtx,
|
|
33
32
|
getServerMidFromUnstableMid: () => getServerMidFromUnstableMid
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(customServer_exports);
|
|
36
35
|
var import_time = require("@modern-js/runtime-utils/time");
|
|
37
36
|
var import_utils = require("../../utils");
|
|
37
|
+
var import_helper = require("../../helper");
|
|
38
38
|
var import_constants = require("../../constants");
|
|
39
|
-
var import_loader = require("./loader");
|
|
40
39
|
var import_context = require("./context");
|
|
41
40
|
var import_base = require("./base");
|
|
42
|
-
var import_loader2 = require("./loader");
|
|
43
41
|
const noop = () => {
|
|
44
42
|
};
|
|
45
43
|
const isHtmlResponse = (response) => {
|
|
@@ -170,7 +168,7 @@ function isRedirect(headers, code) {
|
|
|
170
168
|
].includes(code || 0) || headers.get("Location");
|
|
171
169
|
}
|
|
172
170
|
async function createMiddlewareContextFromHono(c) {
|
|
173
|
-
const loaderContext = (0,
|
|
171
|
+
const loaderContext = (0, import_helper.getLoaderCtx)(c);
|
|
174
172
|
let rawRequest = c.req.raw;
|
|
175
173
|
const method = rawRequest.method.toUpperCase();
|
|
176
174
|
if (![
|
|
@@ -214,6 +212,5 @@ async function createMiddlewareContextFromHono(c) {
|
|
|
214
212
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
213
|
0 && (module.exports = {
|
|
216
214
|
CustomServer,
|
|
217
|
-
getLoaderCtx,
|
|
218
215
|
getServerMidFromUnstableMid
|
|
219
216
|
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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 default_exports = {};
|
|
20
|
+
__export(default_exports, {
|
|
21
|
+
createDefaultPlugins: () => createDefaultPlugins
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(default_exports);
|
|
24
|
+
var import_render = require("./render");
|
|
25
|
+
var import_monitors = require("./monitors");
|
|
26
|
+
var import_processedBy = require("./processedBy");
|
|
27
|
+
var import_log = require("./log");
|
|
28
|
+
function createDefaultPlugins(options = {}) {
|
|
29
|
+
const plugins = [
|
|
30
|
+
(0, import_monitors.initMonitorsPlugin)(),
|
|
31
|
+
(0, import_render.injectRenderHandlerPlugin)(options),
|
|
32
|
+
(0, import_monitors.injectloggerPluigin)(options.logger),
|
|
33
|
+
(0, import_monitors.injectServerTiming)(),
|
|
34
|
+
(0, import_log.logPlugin)(),
|
|
35
|
+
(0, import_processedBy.processedByPlugin)()
|
|
36
|
+
];
|
|
37
|
+
return plugins;
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
createDefaultPlugins
|
|
42
|
+
});
|
|
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var plugins_exports = {};
|
|
20
20
|
__export(plugins_exports, {
|
|
21
|
+
createDefaultPlugins: () => import_default.createDefaultPlugins,
|
|
21
22
|
faviconPlugin: () => import_favicon.faviconPlugin,
|
|
22
|
-
getLoaderCtx: () => import_customServer.getLoaderCtx,
|
|
23
23
|
getRenderHandler: () => import_render.getRenderHandler,
|
|
24
|
-
|
|
24
|
+
injectRenderHandlerPlugin: () => import_render.injectRenderHandlerPlugin,
|
|
25
25
|
injectServerTiming: () => import_monitors.injectServerTiming,
|
|
26
26
|
injectloggerPluigin: () => import_monitors.injectloggerPluigin,
|
|
27
27
|
logPlugin: () => import_log.logPlugin,
|
|
@@ -31,16 +31,16 @@ __export(plugins_exports, {
|
|
|
31
31
|
module.exports = __toCommonJS(plugins_exports);
|
|
32
32
|
var import_render = require("./render");
|
|
33
33
|
var import_favicon = require("./favicon");
|
|
34
|
+
var import_monitors = require("./monitors");
|
|
34
35
|
var import_processedBy = require("./processedBy");
|
|
35
|
-
var import_customServer = require("./customServer");
|
|
36
36
|
var import_log = require("./log");
|
|
37
|
-
var
|
|
37
|
+
var import_default = require("./default");
|
|
38
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
39
|
0 && (module.exports = {
|
|
40
|
+
createDefaultPlugins,
|
|
40
41
|
faviconPlugin,
|
|
41
|
-
getLoaderCtx,
|
|
42
42
|
getRenderHandler,
|
|
43
|
-
|
|
43
|
+
injectRenderHandlerPlugin,
|
|
44
44
|
injectServerTiming,
|
|
45
45
|
injectloggerPluigin,
|
|
46
46
|
logPlugin,
|
|
@@ -90,9 +90,10 @@ const initMonitorsPlugin = () => ({
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
const injectloggerPluigin = (
|
|
93
|
+
const injectloggerPluigin = (inputLogger) => ({
|
|
94
94
|
name: "@modern-js/inject-logger",
|
|
95
95
|
setup(api) {
|
|
96
|
+
const logger = inputLogger || console;
|
|
96
97
|
return {
|
|
97
98
|
prepare() {
|
|
98
99
|
const { middlewares } = api.useAppContext();
|
|
@@ -126,12 +127,12 @@ const injectloggerPluigin = (logger) => ({
|
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
129
|
});
|
|
129
|
-
const injectServerTiming = (
|
|
130
|
+
const injectServerTiming = () => ({
|
|
130
131
|
name: "@modern-js/inject-server-timing",
|
|
131
132
|
setup(api) {
|
|
132
133
|
return {
|
|
133
134
|
prepare() {
|
|
134
|
-
const { middlewares } = api.useAppContext();
|
|
135
|
+
const { middlewares, metaName } = api.useAppContext();
|
|
135
136
|
middlewares.push({
|
|
136
137
|
name: "inject-server-timing",
|
|
137
138
|
handler: async (c, next) => {
|
|
@@ -15,10 +15,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
var render_exports = {};
|
|
20
21
|
__export(render_exports, {
|
|
21
|
-
getRenderHandler: () => getRenderHandler,
|
|
22
22
|
renderPlugin: () => renderPlugin
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(render_exports);
|
|
@@ -26,15 +26,15 @@ var import_constants = require("@modern-js/utils/universal/constants");
|
|
|
26
26
|
var import_monitors = require("../monitors");
|
|
27
27
|
var import_utils = require("../../utils");
|
|
28
28
|
var import_customServer = require("../customServer");
|
|
29
|
-
var
|
|
30
|
-
|
|
29
|
+
var import_helper = require("../../helper");
|
|
30
|
+
__reExport(render_exports, require("./inject"), module.exports);
|
|
31
|
+
const renderPlugin = () => ({
|
|
31
32
|
name: "@modern-js/plugin-render",
|
|
32
33
|
setup(api) {
|
|
33
|
-
const { staticGenerate, cacheConfig } = options;
|
|
34
34
|
return {
|
|
35
35
|
async prepare() {
|
|
36
|
-
var _config_render
|
|
37
|
-
const { middlewares, routes,
|
|
36
|
+
var _config_render;
|
|
37
|
+
const { middlewares, routes, render, distDirectory: pwd, serverBase } = api.useAppContext();
|
|
38
38
|
const runner = api.useHookRunners();
|
|
39
39
|
const config = api.useConfigContext();
|
|
40
40
|
if (!routes) {
|
|
@@ -43,14 +43,6 @@ const renderPlugin = (options = {}) => ({
|
|
|
43
43
|
const customServer = new import_customServer.CustomServer(runner, serverBase, pwd);
|
|
44
44
|
const serverMiddleware = ((_config_render = config.render) === null || _config_render === void 0 ? void 0 : _config_render.middleware) && (0, import_customServer.getServerMidFromUnstableMid)(config.render.middleware);
|
|
45
45
|
const pageRoutes = getPageRoutes(routes);
|
|
46
|
-
const render = await getRenderHandler({
|
|
47
|
-
pwd,
|
|
48
|
-
routes,
|
|
49
|
-
config,
|
|
50
|
-
metaName,
|
|
51
|
-
cacheConfig: ((_config_render1 = config.render) === null || _config_render1 === void 0 ? void 0 : _config_render1.cache) || cacheConfig,
|
|
52
|
-
staticGenerate
|
|
53
|
-
});
|
|
54
46
|
for (const route of pageRoutes) {
|
|
55
47
|
const { urlPath: originUrlPath, entryName } = route;
|
|
56
48
|
const urlPath = originUrlPath.endsWith("/") ? `${originUrlPath}*` : `${originUrlPath}/*`;
|
|
@@ -70,7 +62,7 @@ const renderPlugin = (options = {}) => ({
|
|
|
70
62
|
path: urlPath,
|
|
71
63
|
handler: customServerMiddleware
|
|
72
64
|
});
|
|
73
|
-
middlewares.push({
|
|
65
|
+
render && middlewares.push({
|
|
74
66
|
name: `render`,
|
|
75
67
|
path: urlPath,
|
|
76
68
|
handler: createRenderHandler(render)
|
|
@@ -93,7 +85,7 @@ function createRenderHandler(render) {
|
|
|
93
85
|
const serverManifest = c.get("serverManifest") || {};
|
|
94
86
|
const locals = c.get("locals");
|
|
95
87
|
const metrics = c.get("metrics");
|
|
96
|
-
const loaderContext = (0,
|
|
88
|
+
const loaderContext = (0, import_helper.getLoaderCtx)(c);
|
|
97
89
|
const request = c.req.raw;
|
|
98
90
|
const nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
|
|
99
91
|
const res = await render(request, {
|
|
@@ -115,24 +107,8 @@ function createRenderHandler(render) {
|
|
|
115
107
|
return c.body(body, status, headersData);
|
|
116
108
|
};
|
|
117
109
|
}
|
|
118
|
-
async function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate }) {
|
|
119
|
-
var _config_server, _config_security;
|
|
120
|
-
const ssrConfig = (_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr;
|
|
121
|
-
const forceCSR = typeof ssrConfig === "object" ? ssrConfig.forceCSR : false;
|
|
122
|
-
const render = (0, import_render.createRender)({
|
|
123
|
-
routes,
|
|
124
|
-
pwd,
|
|
125
|
-
config,
|
|
126
|
-
staticGenerate,
|
|
127
|
-
cacheConfig,
|
|
128
|
-
forceCSR,
|
|
129
|
-
nonce: (_config_security = config.security) === null || _config_security === void 0 ? void 0 : _config_security.nonce,
|
|
130
|
-
metaName: metaName || "modern-js"
|
|
131
|
-
});
|
|
132
|
-
return render;
|
|
133
|
-
}
|
|
134
110
|
// Annotate the CommonJS export names for ESM import in node:
|
|
135
111
|
0 && (module.exports = {
|
|
136
|
-
|
|
137
|
-
|
|
112
|
+
renderPlugin,
|
|
113
|
+
...require("./inject")
|
|
138
114
|
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 inject_exports = {};
|
|
20
|
+
__export(inject_exports, {
|
|
21
|
+
getRenderHandler: () => getRenderHandler,
|
|
22
|
+
injectRenderHandlerPlugin: () => injectRenderHandlerPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(inject_exports);
|
|
25
|
+
var import_render = require("./render");
|
|
26
|
+
const injectRenderHandlerPlugin = ({ staticGenerate, cacheConfig }) => ({
|
|
27
|
+
name: "@modern-js/plugin-inject-render",
|
|
28
|
+
setup(api) {
|
|
29
|
+
return {
|
|
30
|
+
async prepare() {
|
|
31
|
+
var _config_render;
|
|
32
|
+
const { distDirectory: pwd, routes, metaName } = api.useAppContext();
|
|
33
|
+
const config = api.useConfigContext();
|
|
34
|
+
if (!routes) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const getRenderHandlerOptions = {
|
|
38
|
+
pwd,
|
|
39
|
+
routes,
|
|
40
|
+
config,
|
|
41
|
+
metaName,
|
|
42
|
+
cacheConfig: ((_config_render = config.render) === null || _config_render === void 0 ? void 0 : _config_render.cache) || cacheConfig,
|
|
43
|
+
staticGenerate
|
|
44
|
+
};
|
|
45
|
+
const render = await getRenderHandler(getRenderHandlerOptions);
|
|
46
|
+
api.setAppContext({
|
|
47
|
+
...api.useAppContext(),
|
|
48
|
+
render,
|
|
49
|
+
getRenderOptions: getRenderHandlerOptions
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
async function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate }) {
|
|
56
|
+
var _config_server, _config_security;
|
|
57
|
+
const ssrConfig = (_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr;
|
|
58
|
+
const forceCSR = typeof ssrConfig === "object" ? ssrConfig.forceCSR : false;
|
|
59
|
+
const render = (0, import_render.createRender)({
|
|
60
|
+
routes,
|
|
61
|
+
pwd,
|
|
62
|
+
config,
|
|
63
|
+
staticGenerate,
|
|
64
|
+
cacheConfig,
|
|
65
|
+
forceCSR,
|
|
66
|
+
nonce: (_config_security = config.security) === null || _config_security === void 0 ? void 0 : _config_security.nonce,
|
|
67
|
+
metaName: metaName || "modern-js"
|
|
68
|
+
});
|
|
69
|
+
return render;
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
getRenderHandler,
|
|
74
|
+
injectRenderHandlerPlugin
|
|
75
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var render_exports = {};
|
|
20
30
|
__export(render_exports, {
|
|
@@ -140,14 +150,35 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
140
150
|
};
|
|
141
151
|
}
|
|
142
152
|
async function renderHandler(request, options, mode, onError) {
|
|
153
|
+
var _options_config_server;
|
|
143
154
|
const serverData = {
|
|
144
155
|
router: {
|
|
145
156
|
baseUrl: options.routeInfo.urlPath,
|
|
146
157
|
params: options.params
|
|
147
158
|
}
|
|
148
159
|
};
|
|
149
|
-
let response;
|
|
150
|
-
|
|
160
|
+
let response = null;
|
|
161
|
+
const { serverManifest } = options;
|
|
162
|
+
const ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
|
|
163
|
+
if (serverManifest.nestedRoutesJson && ssrByRouteIds && (ssrByRouteIds === null || ssrByRouteIds === void 0 ? void 0 : ssrByRouteIds.length) > 0) {
|
|
164
|
+
const { nestedRoutesJson } = serverManifest;
|
|
165
|
+
const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
|
|
166
|
+
if (routes) {
|
|
167
|
+
const { matchRoutes } = await Promise.resolve().then(() => __toESM(require("@modern-js/runtime-utils/remix-router")));
|
|
168
|
+
const url = new URL(request.url);
|
|
169
|
+
const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
|
|
170
|
+
if (!matchedRoutes) {
|
|
171
|
+
response = csrRender(options.html);
|
|
172
|
+
} else {
|
|
173
|
+
var _lastMatch_route;
|
|
174
|
+
const lastMatch = matchedRoutes[matchedRoutes.length - 1];
|
|
175
|
+
if (!(lastMatch === null || lastMatch === void 0 ? void 0 : (_lastMatch_route = lastMatch.route) === null || _lastMatch_route === void 0 ? void 0 : _lastMatch_route.id) || !ssrByRouteIds.includes(lastMatch.route.id)) {
|
|
176
|
+
response = csrRender(options.html);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (mode === "ssr" && !response) {
|
|
151
182
|
try {
|
|
152
183
|
response = await (0, import_ssrRender.ssrRender)(request, options);
|
|
153
184
|
} catch (e) {
|
|
@@ -29,8 +29,8 @@ function loadServerRuntimeConfig(pwd) {
|
|
|
29
29
|
}
|
|
30
30
|
function loadServerCliConfig(pwd) {
|
|
31
31
|
var defaultConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
32
|
-
var _defaultConfig_output;
|
|
33
|
-
var cliConfigPath = ensureAbsolutePath(pwd, path.join(((_defaultConfig_output = defaultConfig.output) === null || _defaultConfig_output === void 0 ? void 0 : _defaultConfig_output.
|
|
32
|
+
var _defaultConfig_output_distPath, _defaultConfig_output;
|
|
33
|
+
var cliConfigPath = ensureAbsolutePath(pwd, path.join(((_defaultConfig_output = defaultConfig.output) === null || _defaultConfig_output === void 0 ? void 0 : (_defaultConfig_output_distPath = _defaultConfig_output.distPath) === null || _defaultConfig_output_distPath === void 0 ? void 0 : _defaultConfig_output_distPath.root) || "dist", OUTPUT_CONFIG_FILE));
|
|
34
34
|
var cliConfig = {
|
|
35
35
|
output: {},
|
|
36
36
|
source: {},
|
|
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
6
|
-
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs } from "@modern-js/utils";
|
|
6
|
+
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs } from "@modern-js/utils";
|
|
7
7
|
function getHtmlTemplates(pwd, routes) {
|
|
8
8
|
return _getHtmlTemplates.apply(this, arguments);
|
|
9
9
|
}
|
|
@@ -153,7 +153,7 @@ function getServerManifest(pwd, routes, logger) {
|
|
|
153
153
|
}
|
|
154
154
|
function _getServerManifest() {
|
|
155
155
|
_getServerManifest = _async_to_generator(function(pwd, routes, logger) {
|
|
156
|
-
var loaderBundles, renderBundles, loadableUri, loadableStats, routesManifestUri, routeManifest;
|
|
156
|
+
var loaderBundles, renderBundles, loadableUri, loadableStats, routesManifestUri, routeManifest, nestedRoutesJsonPath, nestedRoutesJson;
|
|
157
157
|
return _ts_generator(this, function(_state) {
|
|
158
158
|
switch (_state.label) {
|
|
159
159
|
case 0:
|
|
@@ -217,13 +217,23 @@ function _getServerManifest() {
|
|
|
217
217
|
];
|
|
218
218
|
case 3:
|
|
219
219
|
routeManifest = _state.sent();
|
|
220
|
+
nestedRoutesJsonPath = path.join(pwd, NESTED_ROUTE_SPEC_FILE);
|
|
221
|
+
return [
|
|
222
|
+
4,
|
|
223
|
+
import(nestedRoutesJsonPath).catch(function(_) {
|
|
224
|
+
return {};
|
|
225
|
+
})
|
|
226
|
+
];
|
|
227
|
+
case 4:
|
|
228
|
+
nestedRoutesJson = _state.sent();
|
|
220
229
|
return [
|
|
221
230
|
2,
|
|
222
231
|
{
|
|
223
232
|
loaderBundles,
|
|
224
233
|
renderBundles,
|
|
225
234
|
loadableStats,
|
|
226
|
-
routeManifest
|
|
235
|
+
routeManifest,
|
|
236
|
+
nestedRoutesJson
|
|
227
237
|
}
|
|
228
238
|
];
|
|
229
239
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
var LOADER_CONTEXT = "loaderContext";
|
|
1
2
|
function getLoaderCtx(c) {
|
|
2
|
-
var loaderContext = c.get(
|
|
3
|
+
var loaderContext = c.get(LOADER_CONTEXT);
|
|
3
4
|
if (loaderContext) {
|
|
4
5
|
return loaderContext;
|
|
5
6
|
} else {
|
|
6
7
|
var loaderContext1 = /* @__PURE__ */ new Map();
|
|
7
|
-
c.set(
|
|
8
|
+
c.set(LOADER_CONTEXT, loaderContext1);
|
|
8
9
|
return loaderContext1;
|
|
9
10
|
}
|
|
10
11
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createErrorHtml, onError, ErrorDigest } from "./utils";
|
|
|
2
2
|
import { AGGRED_DIR } from "./constants";
|
|
3
3
|
import { createServerBase } from "./serverBase";
|
|
4
4
|
import { PluginManager } from "./pluginManager";
|
|
5
|
+
import { getLoaderCtx } from "./helper";
|
|
5
6
|
export * from "./plugins";
|
|
6
7
|
export * from "./types/plugin";
|
|
7
8
|
export * from "./types/render";
|
|
@@ -14,5 +15,6 @@ export {
|
|
|
14
15
|
PluginManager,
|
|
15
16
|
createErrorHtml,
|
|
16
17
|
createServerBase,
|
|
18
|
+
getLoaderCtx,
|
|
17
19
|
onError
|
|
18
20
|
};
|
|
@@ -178,6 +178,9 @@ var BaseHookResponse = /* @__PURE__ */ function() {
|
|
|
178
178
|
_class_private_field_get(this, _c1).status(code);
|
|
179
179
|
_class_private_field_get(this, _resArgs) && (_class_private_field_get(this, _resArgs).status = code);
|
|
180
180
|
};
|
|
181
|
+
_proto.getStatus = function getStatus() {
|
|
182
|
+
return _class_private_field_get(this, _c1).res.status;
|
|
183
|
+
};
|
|
181
184
|
_proto.raw = function raw(body, options) {
|
|
182
185
|
_class_private_field_get(this, _c1).res = _class_private_field_get(this, _c1).newResponse(body, options);
|
|
183
186
|
this.private_overrided = true;
|
|
@@ -3,11 +3,10 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import { time } from "@modern-js/runtime-utils/time";
|
|
5
5
|
import { transformResponse } from "../../utils";
|
|
6
|
+
import { getLoaderCtx } from "../../helper";
|
|
6
7
|
import { ServerTimings } from "../../constants";
|
|
7
|
-
import { getLoaderCtx } from "./loader";
|
|
8
8
|
import { getAfterMatchCtx, getAfterRenderCtx, createCustomMiddlewaresCtx, createAfterStreamingRenderContext } from "./context";
|
|
9
9
|
import { createBaseHookContext } from "./base";
|
|
10
|
-
import { getLoaderCtx as getLoaderCtx2 } from "./loader";
|
|
11
10
|
var noop = function() {
|
|
12
11
|
};
|
|
13
12
|
var isHtmlResponse = function(response) {
|
|
@@ -346,6 +345,5 @@ function _createMiddlewareContextFromHono() {
|
|
|
346
345
|
}
|
|
347
346
|
export {
|
|
348
347
|
CustomServer,
|
|
349
|
-
getLoaderCtx2 as getLoaderCtx,
|
|
350
348
|
getServerMidFromUnstableMid
|
|
351
349
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { injectRenderHandlerPlugin } from "./render";
|
|
2
|
+
import { initMonitorsPlugin, injectloggerPluigin, injectServerTiming } from "./monitors";
|
|
3
|
+
import { processedByPlugin } from "./processedBy";
|
|
4
|
+
import { logPlugin } from "./log";
|
|
5
|
+
function createDefaultPlugins() {
|
|
6
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
7
|
+
var plugins = [
|
|
8
|
+
initMonitorsPlugin(),
|
|
9
|
+
injectRenderHandlerPlugin(options),
|
|
10
|
+
injectloggerPluigin(options.logger),
|
|
11
|
+
injectServerTiming(),
|
|
12
|
+
logPlugin(),
|
|
13
|
+
processedByPlugin()
|
|
14
|
+
];
|
|
15
|
+
return plugins;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
createDefaultPlugins
|
|
19
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { renderPlugin, getRenderHandler } from "./render";
|
|
1
|
+
import { renderPlugin, injectRenderHandlerPlugin, getRenderHandler } from "./render";
|
|
2
2
|
import { faviconPlugin } from "./favicon";
|
|
3
|
+
import { injectServerTiming, injectloggerPluigin } from "./monitors";
|
|
3
4
|
import { processedByPlugin } from "./processedBy";
|
|
4
|
-
import { getLoaderCtx } from "./customServer";
|
|
5
5
|
import { logPlugin } from "./log";
|
|
6
|
-
import {
|
|
6
|
+
import { createDefaultPlugins } from "./default";
|
|
7
7
|
export {
|
|
8
|
+
createDefaultPlugins,
|
|
8
9
|
faviconPlugin,
|
|
9
|
-
getLoaderCtx,
|
|
10
10
|
getRenderHandler,
|
|
11
|
-
|
|
11
|
+
injectRenderHandlerPlugin,
|
|
12
12
|
injectServerTiming,
|
|
13
13
|
injectloggerPluigin,
|
|
14
14
|
logPlugin,
|
|
@@ -96,10 +96,11 @@ var initMonitorsPlugin = function() {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
};
|
|
99
|
-
var injectloggerPluigin = function(
|
|
99
|
+
var injectloggerPluigin = function(inputLogger) {
|
|
100
100
|
return {
|
|
101
101
|
name: "@modern-js/inject-logger",
|
|
102
102
|
setup: function setup(api) {
|
|
103
|
+
var logger = inputLogger || console;
|
|
103
104
|
return {
|
|
104
105
|
prepare: function prepare() {
|
|
105
106
|
var middlewares = api.useAppContext().middlewares;
|
|
@@ -149,13 +150,12 @@ var injectloggerPluigin = function(logger) {
|
|
|
149
150
|
};
|
|
150
151
|
};
|
|
151
152
|
var injectServerTiming = function() {
|
|
152
|
-
var metaName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "modern-js";
|
|
153
153
|
return {
|
|
154
154
|
name: "@modern-js/inject-server-timing",
|
|
155
155
|
setup: function setup(api) {
|
|
156
156
|
return {
|
|
157
157
|
prepare: function prepare() {
|
|
158
|
-
var
|
|
158
|
+
var _api_useAppContext = api.useAppContext(), middlewares = _api_useAppContext.middlewares, metaName = _api_useAppContext.metaName;
|
|
159
159
|
middlewares.push({
|
|
160
160
|
name: "inject-server-timing",
|
|
161
161
|
handler: function() {
|