@modern-js/server-core 2.58.3-alpha.1 → 2.58.3
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/hono.js +13 -6
- package/dist/cjs/adapters/node/node.js +2 -2
- package/dist/cjs/adapters/node/plugins/resource.js +1 -1
- package/dist/cjs/adapters/node/plugins/static.js +1 -1
- package/dist/cjs/adapters/node/polyfills/install.js +1 -1
- package/dist/cjs/plugins/customServer/base.js +3 -1
- package/dist/cjs/plugins/customServer/context.js +1 -1
- package/dist/cjs/plugins/customServer/index.js +4 -11
- package/dist/cjs/plugins/default.js +2 -2
- package/dist/cjs/plugins/render/index.js +5 -3
- package/dist/cjs/plugins/render/render.js +17 -22
- package/dist/cjs/plugins/render/ssrRender.js +1 -1
- package/dist/cjs/serverBase.js +1 -1
- package/dist/esm/adapters/node/helper/loadConfig.js +1 -1
- package/dist/esm/adapters/node/hono.js +29 -15
- package/dist/esm/adapters/node/node.js +2 -2
- package/dist/esm/adapters/node/plugins/resource.js +31 -3
- package/dist/esm/adapters/node/plugins/static.js +1 -1
- package/dist/esm/adapters/node/polyfills/install.js +3 -3
- package/dist/esm/plugins/customServer/base.js +7 -1
- package/dist/esm/plugins/customServer/context.js +1 -1
- package/dist/esm/plugins/customServer/index.js +5 -15
- package/dist/esm/plugins/default.js +3 -3
- package/dist/esm/plugins/render/index.js +6 -4
- package/dist/esm/plugins/render/render.js +9 -13
- package/dist/esm/plugins/render/ssrRender.js +2 -2
- package/dist/esm/serverBase.js +1 -1
- package/dist/esm-node/adapters/node/helper/loadConfig.js +1 -1
- package/dist/esm-node/adapters/node/hono.js +13 -6
- package/dist/esm-node/adapters/node/node.js +2 -2
- package/dist/esm-node/adapters/node/plugins/resource.js +2 -2
- package/dist/esm-node/adapters/node/plugins/static.js +1 -1
- package/dist/esm-node/adapters/node/polyfills/install.js +3 -3
- package/dist/esm-node/plugins/customServer/base.js +3 -1
- package/dist/esm-node/plugins/customServer/context.js +1 -1
- package/dist/esm-node/plugins/customServer/index.js +4 -11
- package/dist/esm-node/plugins/default.js +3 -3
- package/dist/esm-node/plugins/render/index.js +5 -3
- package/dist/esm-node/plugins/render/render.js +8 -13
- package/dist/esm-node/plugins/render/ssrRender.js +2 -2
- package/dist/esm-node/serverBase.js +1 -1
- package/dist/types/adapters/node/hono.d.ts +4 -2
- package/dist/types/adapters/node/plugins/nodeServer.d.ts +1 -1
- package/dist/types/adapters/node/plugins/static.d.ts +1 -1
- package/dist/types/pluginManager.d.ts +1 -1
- package/dist/types/plugins/customServer/context.d.ts +2 -2
- package/dist/types/plugins/customServer/index.d.ts +2 -2
- package/dist/types/plugins/render/ssrRender.d.ts +2 -2
- package/dist/types/serverBase.d.ts +1 -0
- package/dist/types/types/config/bff.d.ts +1 -1
- package/dist/types/types/config/server.d.ts +0 -23
- package/dist/types/types/plugin.d.ts +2 -2
- package/dist/types/types/render.d.ts +2 -0
- package/dist/types/types/requestHandler.d.ts +1 -1
- package/dist/types/types/server.d.ts +2 -1
- package/package.json +7 -7
|
@@ -25,15 +25,22 @@ module.exports = __toCommonJS(hono_exports);
|
|
|
25
25
|
const httpCallBack2HonoMid = (handler) => {
|
|
26
26
|
return async (context, next) => {
|
|
27
27
|
const { req, res } = context.env.node;
|
|
28
|
+
const onPipe = () => {
|
|
29
|
+
res._modernBodyPiped = true;
|
|
30
|
+
};
|
|
31
|
+
res.once("pipe", onPipe);
|
|
28
32
|
req.__honoRequest = context.req;
|
|
29
33
|
req.__templates = context.get("templates") || {};
|
|
30
34
|
req.__serverManifest = context.get("serverManifest") || {};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
try {
|
|
36
|
+
await handler(req, res);
|
|
37
|
+
} finally {
|
|
38
|
+
delete req.__honoRequest;
|
|
39
|
+
delete req.__templates;
|
|
40
|
+
delete req.__serverManifest;
|
|
41
|
+
res.removeListener("pipe", onPipe);
|
|
42
|
+
}
|
|
43
|
+
if (res.headersSent || res._modernBodyPiped) {
|
|
37
44
|
context.finalized = true;
|
|
38
45
|
} else {
|
|
39
46
|
await next();
|
|
@@ -35,8 +35,8 @@ __export(node_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(node_exports);
|
|
37
37
|
var import_node_http = require("node:http");
|
|
38
|
-
var import_stream = require("./polyfills/stream");
|
|
39
38
|
var import_install = require("./polyfills/install");
|
|
39
|
+
var import_stream = require("./polyfills/stream");
|
|
40
40
|
var import_polyfills = require("./polyfills");
|
|
41
41
|
(0, import_install.installGlobals)();
|
|
42
42
|
const createWebRequest = (req, res, body) => {
|
|
@@ -116,7 +116,7 @@ const getRequestListener = (handler) => {
|
|
|
116
116
|
res
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
|
-
if (!res.headersSent && !response.res) {
|
|
119
|
+
if (!res.headersSent && !response.res && !res._modernBodyPiped) {
|
|
120
120
|
await sendResponse(response, res);
|
|
121
121
|
}
|
|
122
122
|
} catch (error) {
|
|
@@ -86,7 +86,7 @@ async function getServerManifest(pwd, routes, logger) {
|
|
|
86
86
|
const renderBundle = await loadBundle(renderBundlePath, logger);
|
|
87
87
|
const loaderBundle = await loadBundle(loaderBundlePath, logger);
|
|
88
88
|
renderBundle && (renderBundles[entryName] = renderBundle);
|
|
89
|
-
loaderBundle && (loaderBundles[entryName] = loaderBundle);
|
|
89
|
+
loaderBundle && (loaderBundles[entryName] = (loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules) ? await (loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules()) : loaderBundle);
|
|
90
90
|
}));
|
|
91
91
|
const loadableUri = import_path.default.join(pwd, import_utils.LOADABLE_STATS_FILE);
|
|
92
92
|
const loadableStats = await (0, import_utils.compatibleRequire)(loadableUri).catch((_) => ({}));
|
|
@@ -34,9 +34,9 @@ __export(static_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(static_exports);
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_fileReader = require("@modern-js/runtime-utils/fileReader");
|
|
37
38
|
var import_utils = require("@modern-js/utils");
|
|
38
39
|
var import_mime = require("hono/utils/mime");
|
|
39
|
-
var import_fileReader = require("@modern-js/runtime-utils/fileReader");
|
|
40
40
|
var import_utils2 = require("../../../utils");
|
|
41
41
|
const serverStaticPlugin = () => ({
|
|
42
42
|
name: "@modern-js/plugin-server-static",
|
|
@@ -22,8 +22,8 @@ __export(install_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(install_exports);
|
|
24
24
|
var import_fetch = require("@web-std/fetch");
|
|
25
|
-
var import_stream = require("@web-std/stream");
|
|
26
25
|
var import_file = require("@web-std/file");
|
|
26
|
+
var import_stream = require("@web-std/stream");
|
|
27
27
|
if (!Object.getOwnPropertyDescriptor(import_fetch.Headers.prototype, "getSetCookie")) {
|
|
28
28
|
Object.defineProperty(import_fetch.Headers.prototype, "getSetCookie", {
|
|
29
29
|
value: function getSetCookie() {
|
|
@@ -39,7 +39,9 @@ function createBaseHookContext(c, resParams) {
|
|
|
39
39
|
var _req = /* @__PURE__ */ new WeakMap(), _c = /* @__PURE__ */ new WeakMap(), _headersData = /* @__PURE__ */ new WeakMap(), _headers = /* @__PURE__ */ new WeakMap();
|
|
40
40
|
class BaseHookRequest {
|
|
41
41
|
get url() {
|
|
42
|
-
|
|
42
|
+
const query = (0, import_class_private_field_get._)(this, _c).req.query();
|
|
43
|
+
const q = Object.entries(query).map(([key, value]) => `${key}=${value}`).join("&");
|
|
44
|
+
return q ? `${(0, import_class_private_field_get._)(this, _c).req.path}?${q}` : (0, import_class_private_field_get._)(this, _c).req.path;
|
|
43
45
|
}
|
|
44
46
|
// TODO: remove next major version
|
|
45
47
|
set url(_u) {
|
|
@@ -24,9 +24,9 @@ __export(context_exports, {
|
|
|
24
24
|
getAfterRenderCtx: () => getAfterRenderCtx
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(context_exports);
|
|
27
|
+
var import_base = require("./base");
|
|
27
28
|
var import_routerApi = require("./routerApi");
|
|
28
29
|
var import_template = require("./template");
|
|
29
|
-
var import_base = require("./base");
|
|
30
30
|
function getAfterMatchCtx(entryName, baseHookCtx) {
|
|
31
31
|
const afterMatchCtx = baseHookCtx;
|
|
32
32
|
afterMatchCtx.router = new import_routerApi.RouterAPI(entryName);
|
|
@@ -33,11 +33,11 @@ __export(customServer_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(customServer_exports);
|
|
35
35
|
var import_time = require("@modern-js/runtime-utils/time");
|
|
36
|
-
var import_utils = require("../../utils");
|
|
37
|
-
var import_helper = require("../../helper");
|
|
38
36
|
var import_constants = require("../../constants");
|
|
39
|
-
var
|
|
37
|
+
var import_helper = require("../../helper");
|
|
38
|
+
var import_utils = require("../../utils");
|
|
40
39
|
var import_base = require("./base");
|
|
40
|
+
var import_context = require("./context");
|
|
41
41
|
const noop = () => {
|
|
42
42
|
};
|
|
43
43
|
const isHtmlResponse = (response) => {
|
|
@@ -65,14 +65,7 @@ class CustomServer {
|
|
|
65
65
|
if (current !== entryName) {
|
|
66
66
|
const rewriteRoute = routes.find((route) => route.entryName === current);
|
|
67
67
|
if (rewriteRoute) {
|
|
68
|
-
|
|
69
|
-
const url2 = new URL(c.req.url);
|
|
70
|
-
const newUrl = new URL(rewriteRoute.urlPath, url2.origin);
|
|
71
|
-
return this.serverBase.request(newUrl, {
|
|
72
|
-
headers,
|
|
73
|
-
method,
|
|
74
|
-
signal
|
|
75
|
-
}, c.env);
|
|
68
|
+
c.set("matchPathname", rewriteRoute.urlPath);
|
|
76
69
|
}
|
|
77
70
|
}
|
|
78
71
|
if (c.finalized) {
|
|
@@ -21,10 +21,10 @@ __export(default_exports, {
|
|
|
21
21
|
createDefaultPlugins: () => createDefaultPlugins
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(default_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_log = require("./log");
|
|
25
25
|
var import_monitors = require("./monitors");
|
|
26
26
|
var import_processedBy = require("./processedBy");
|
|
27
|
-
var
|
|
27
|
+
var import_render = require("./render");
|
|
28
28
|
function createDefaultPlugins(options = {}) {
|
|
29
29
|
const plugins = [
|
|
30
30
|
(0, import_monitors.initMonitorsPlugin)(),
|
|
@@ -23,10 +23,10 @@ __export(render_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(render_exports);
|
|
25
25
|
var import_constants = require("@modern-js/utils/universal/constants");
|
|
26
|
-
var
|
|
26
|
+
var import_helper = require("../../helper");
|
|
27
27
|
var import_utils = require("../../utils");
|
|
28
28
|
var import_customServer = require("../customServer");
|
|
29
|
-
var
|
|
29
|
+
var import_monitors = require("../monitors");
|
|
30
30
|
__reExport(render_exports, require("./inject"), module.exports);
|
|
31
31
|
const renderPlugin = () => ({
|
|
32
32
|
name: "@modern-js/plugin-render",
|
|
@@ -85,6 +85,7 @@ function createRenderHandler(render) {
|
|
|
85
85
|
const serverManifest = c.get("serverManifest") || {};
|
|
86
86
|
const locals = c.get("locals");
|
|
87
87
|
const metrics = c.get("metrics");
|
|
88
|
+
const matchPathname = c.get("matchPathname");
|
|
88
89
|
const loaderContext = (0, import_helper.getLoaderCtx)(c);
|
|
89
90
|
const request = c.req.raw;
|
|
90
91
|
const nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
|
|
@@ -97,7 +98,8 @@ function createRenderHandler(render) {
|
|
|
97
98
|
metrics,
|
|
98
99
|
serverManifest,
|
|
99
100
|
loaderContext,
|
|
100
|
-
locals
|
|
101
|
+
locals,
|
|
102
|
+
matchPathname
|
|
101
103
|
});
|
|
102
104
|
const { body, status, headers } = res;
|
|
103
105
|
const headersData = {};
|
|
@@ -31,13 +31,13 @@ __export(render_exports, {
|
|
|
31
31
|
createRender: () => createRender
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(render_exports);
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
34
35
|
var import_universal = require("@modern-js/utils/universal");
|
|
35
36
|
var import_trie_router = require("hono/router/trie-router");
|
|
36
|
-
var import_utils = require("../../utils");
|
|
37
37
|
var import_constants = require("../../constants");
|
|
38
|
+
var import_utils2 = require("../../utils");
|
|
38
39
|
var import_dataHandler = require("./dataHandler");
|
|
39
40
|
var import_ssrRender = require("./ssrRender");
|
|
40
|
-
var import_utils2 = require("@modern-js/utils");
|
|
41
41
|
const DYNAMIC_ROUTE_REG = /\/:./;
|
|
42
42
|
function getRouter(routes) {
|
|
43
43
|
const dynamicRoutes = [];
|
|
@@ -50,8 +50,8 @@ function getRouter(routes) {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
const finalRoutes = [
|
|
53
|
-
...normalRoutes.sort(
|
|
54
|
-
...dynamicRoutes.sort(
|
|
53
|
+
...normalRoutes.sort(import_utils2.sortRoutes),
|
|
54
|
+
...dynamicRoutes.sort(import_utils2.sortRoutes)
|
|
55
55
|
];
|
|
56
56
|
const router = new import_trie_router.TrieRouter();
|
|
57
57
|
for (const route of finalRoutes) {
|
|
@@ -61,8 +61,7 @@ function getRouter(routes) {
|
|
|
61
61
|
}
|
|
62
62
|
return router;
|
|
63
63
|
}
|
|
64
|
-
function matchRoute(router,
|
|
65
|
-
const pathname = (0, import_utils.getPathname)(request);
|
|
64
|
+
function matchRoute(router, pathname) {
|
|
66
65
|
const matched = router.match("*", pathname);
|
|
67
66
|
const result = matched[0][0];
|
|
68
67
|
return result || [];
|
|
@@ -77,8 +76,9 @@ function getHeadersWithoutCookie(headers) {
|
|
|
77
76
|
}
|
|
78
77
|
async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, config, onFallback: onFallbackFn }) {
|
|
79
78
|
const router = getRouter(routes);
|
|
80
|
-
return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, loaderContext }) => {
|
|
81
|
-
const
|
|
79
|
+
return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext }) => {
|
|
80
|
+
const forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : (0, import_utils2.getPathname)(req);
|
|
81
|
+
const [routeInfo, params] = matchRoute(router, forMatchpathname);
|
|
82
82
|
const onFallback = async (reason, error) => {
|
|
83
83
|
return onFallbackFn === null || onFallbackFn === void 0 ? void 0 : onFallbackFn(reason, {
|
|
84
84
|
logger,
|
|
@@ -87,7 +87,7 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
87
87
|
}, error);
|
|
88
88
|
};
|
|
89
89
|
if (!routeInfo) {
|
|
90
|
-
return new Response((0,
|
|
90
|
+
return new Response((0, import_utils2.createErrorHtml)(404), {
|
|
91
91
|
status: 404,
|
|
92
92
|
headers: {
|
|
93
93
|
"content-type": "text/html; charset=UTF-8"
|
|
@@ -96,7 +96,7 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
96
96
|
}
|
|
97
97
|
const html = templates[routeInfo.entryName];
|
|
98
98
|
if (!html) {
|
|
99
|
-
return new Response((0,
|
|
99
|
+
return new Response((0, import_utils2.createErrorHtml)(404), {
|
|
100
100
|
status: 404,
|
|
101
101
|
headers: {
|
|
102
102
|
"content-type": "text/html; charset=UTF-8"
|
|
@@ -104,16 +104,16 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
const renderMode = await getRenderMode(req, metaName || "modern-js", routeInfo.isSSR, forceCSR, nodeReq, onFallback);
|
|
107
|
-
const pathname = (0,
|
|
108
|
-
const headerData = (0,
|
|
107
|
+
const pathname = (0, import_utils2.getPathname)(req);
|
|
108
|
+
const headerData = (0, import_utils2.parseHeaders)(req);
|
|
109
109
|
const onError = (e) => {
|
|
110
|
-
monitors === null || monitors === void 0 ? void 0 : monitors.error(`SSR Error - ${e instanceof Error ? e.name : e}, error = %s, req.url = %s, req.headers = %o`, e instanceof Error ? e.stack || e.message : e,
|
|
110
|
+
monitors === null || monitors === void 0 ? void 0 : monitors.error(`SSR Error - ${e instanceof Error ? e.name : e}, error = %s, req.url = %s, req.headers = %o`, e instanceof Error ? e.stack || e.message : e, forMatchpathname, getHeadersWithoutCookie(headerData));
|
|
111
111
|
};
|
|
112
112
|
const onTiming = (name, dur) => {
|
|
113
113
|
monitors === null || monitors === void 0 ? void 0 : monitors.timing(name, dur, "SSR");
|
|
114
114
|
};
|
|
115
115
|
const onBoundError = async (e) => {
|
|
116
|
-
(0,
|
|
116
|
+
(0, import_utils2.onError)(import_utils2.ErrorDigest.ERENDER, e, monitors, req);
|
|
117
117
|
await (onFallback === null || onFallback === void 0 ? void 0 : onFallback("error", e));
|
|
118
118
|
};
|
|
119
119
|
const renderOptions = {
|
|
@@ -165,7 +165,7 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
165
165
|
const { nestedRoutesJson } = serverManifest;
|
|
166
166
|
const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
|
|
167
167
|
if (routes) {
|
|
168
|
-
const { matchRoutes } = await (0,
|
|
168
|
+
const { matchRoutes } = await (0, import_utils.compatibleRequire)(require.resolve("@modern-js/runtime-utils/remix-router"), false);
|
|
169
169
|
const url = new URL(request.url);
|
|
170
170
|
const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
|
|
171
171
|
if (!matchedRoutes) {
|
|
@@ -189,12 +189,7 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
189
189
|
} else {
|
|
190
190
|
response = csrRender(options.html);
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
if (!options.staticGenerate) {
|
|
194
|
-
newRes = (0, import_utils.transformResponse)(response, injectServerData(serverData));
|
|
195
|
-
} else {
|
|
196
|
-
newRes = response;
|
|
197
|
-
}
|
|
192
|
+
const newRes = (0, import_utils2.transformResponse)(response, injectServerData(serverData));
|
|
198
193
|
const { routeInfo } = options;
|
|
199
194
|
applyExtendHeaders(newRes, routeInfo);
|
|
200
195
|
return newRes;
|
|
@@ -205,7 +200,7 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
205
200
|
}
|
|
206
201
|
}
|
|
207
202
|
async function getRenderMode(req, framework, isSSR, forceCSR, nodeReq, onFallback) {
|
|
208
|
-
const query = (0,
|
|
203
|
+
const query = (0, import_utils2.parseQuery)(req);
|
|
209
204
|
const fallbackHeader = `x-${(0, import_universal.cutNameByHyphen)(framework)}-ssr-fallback`;
|
|
210
205
|
if (isSSR) {
|
|
211
206
|
if (query.__loader) {
|
|
@@ -22,8 +22,8 @@ __export(ssrRender_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ssrRender_exports);
|
|
24
24
|
var import_constants = require("@modern-js/utils/universal/constants");
|
|
25
|
-
var import_utils = require("../../utils");
|
|
26
25
|
var import_constants2 = require("../../constants");
|
|
26
|
+
var import_utils = require("../../utils");
|
|
27
27
|
var import_ssrCache = require("./ssrCache");
|
|
28
28
|
const SERVER_RUNTIME_ENTRY = "requestHandler";
|
|
29
29
|
async function ssrRender(request, { routeInfo, html, config: userConfig, staticGenerate, nodeReq, serverManifest, locals, params, loaderContext, reporter, cacheConfig, logger, metrics, onError, onTiming }) {
|
package/dist/cjs/serverBase.js
CHANGED
|
@@ -24,8 +24,8 @@ __export(serverBase_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(serverBase_exports);
|
|
25
25
|
var import_class_private_method_get = require("@swc/helpers/_/_class_private_method_get");
|
|
26
26
|
var import_class_private_method_init = require("@swc/helpers/_/_class_private_method_init");
|
|
27
|
-
var import_hono = require("hono");
|
|
28
27
|
var import_plugin = require("@modern-js/plugin");
|
|
28
|
+
var import_hono = require("hono");
|
|
29
29
|
var import_pluginManager = require("./pluginManager");
|
|
30
30
|
var _getAppContext = /* @__PURE__ */ new WeakSet(), _applyMiddlewares = /* @__PURE__ */ new WeakSet();
|
|
31
31
|
class ServerBase {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { fs, DEFAULT_SERVER_CONFIG,
|
|
4
|
+
import { fs, DEFAULT_SERVER_CONFIG, OUTPUT_CONFIG_FILE, lodash as _, compatibleRequire, ensureAbsolutePath, requireExistModule } from "@modern-js/utils";
|
|
5
5
|
import { parse } from "flatted";
|
|
6
6
|
var requireConfig = function() {
|
|
7
7
|
var _ref = _async_to_generator(function(serverConfigPath) {
|
|
@@ -3,50 +3,64 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
3
3
|
var httpCallBack2HonoMid = function(handler) {
|
|
4
4
|
return function() {
|
|
5
5
|
var _ref = _async_to_generator(function(context, next) {
|
|
6
|
-
var _context_env_node, req, res;
|
|
6
|
+
var _context_env_node, req, res, onPipe;
|
|
7
7
|
return _ts_generator(this, function(_state) {
|
|
8
8
|
switch (_state.label) {
|
|
9
9
|
case 0:
|
|
10
10
|
_context_env_node = context.env.node, req = _context_env_node.req, res = _context_env_node.res;
|
|
11
|
+
onPipe = function() {
|
|
12
|
+
res._modernBodyPiped = true;
|
|
13
|
+
};
|
|
14
|
+
res.once("pipe", onPipe);
|
|
11
15
|
req.__honoRequest = context.req;
|
|
12
16
|
req.__templates = context.get("templates") || {};
|
|
13
17
|
req.__serverManifest = context.get("serverManifest") || {};
|
|
18
|
+
_state.label = 1;
|
|
19
|
+
case 1:
|
|
20
|
+
_state.trys.push([
|
|
21
|
+
1,
|
|
22
|
+
,
|
|
23
|
+
3,
|
|
24
|
+
4
|
|
25
|
+
]);
|
|
14
26
|
return [
|
|
15
27
|
4,
|
|
16
28
|
handler(req, res)
|
|
17
29
|
];
|
|
18
|
-
case
|
|
30
|
+
case 2:
|
|
19
31
|
_state.sent();
|
|
20
32
|
return [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return setTimeout(resolve, 0);
|
|
24
|
-
})
|
|
33
|
+
3,
|
|
34
|
+
4
|
|
25
35
|
];
|
|
26
|
-
case
|
|
27
|
-
_state.sent();
|
|
36
|
+
case 3:
|
|
28
37
|
delete req.__honoRequest;
|
|
29
38
|
delete req.__templates;
|
|
30
39
|
delete req.__serverManifest;
|
|
31
|
-
|
|
40
|
+
res.removeListener("pipe", onPipe);
|
|
41
|
+
return [
|
|
42
|
+
7
|
|
43
|
+
];
|
|
44
|
+
case 4:
|
|
45
|
+
if (!(res.headersSent || res._modernBodyPiped))
|
|
32
46
|
return [
|
|
33
47
|
3,
|
|
34
|
-
|
|
48
|
+
5
|
|
35
49
|
];
|
|
36
50
|
context.finalized = true;
|
|
37
51
|
return [
|
|
38
52
|
3,
|
|
39
|
-
|
|
53
|
+
7
|
|
40
54
|
];
|
|
41
|
-
case
|
|
55
|
+
case 5:
|
|
42
56
|
return [
|
|
43
57
|
4,
|
|
44
58
|
next()
|
|
45
59
|
];
|
|
46
|
-
case
|
|
60
|
+
case 6:
|
|
47
61
|
_state.sent();
|
|
48
|
-
_state.label =
|
|
49
|
-
case
|
|
62
|
+
_state.label = 7;
|
|
63
|
+
case 7:
|
|
50
64
|
return [
|
|
51
65
|
2
|
|
52
66
|
];
|
|
@@ -3,8 +3,8 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import { ServerResponse } from "node:http";
|
|
6
|
-
import { createReadableStreamFromReadable, writeReadableStreamToWritable } from "./polyfills/stream";
|
|
7
6
|
import { installGlobals } from "./polyfills/install";
|
|
7
|
+
import { createReadableStreamFromReadable, writeReadableStreamToWritable } from "./polyfills/stream";
|
|
8
8
|
import { writeReadableStreamToWritable as writeReadableStreamToWritable2 } from "./polyfills";
|
|
9
9
|
installGlobals();
|
|
10
10
|
var createWebRequest = function(req, res, body) {
|
|
@@ -145,7 +145,7 @@ var getRequestListener = function(handler) {
|
|
|
145
145
|
];
|
|
146
146
|
case 1:
|
|
147
147
|
response = _state.sent();
|
|
148
|
-
if (!(!res.headersSent && !response.res))
|
|
148
|
+
if (!(!res.headersSent && !response.res && !res._modernBodyPiped))
|
|
149
149
|
return [
|
|
150
150
|
3,
|
|
151
151
|
3
|
|
@@ -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, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY,
|
|
6
|
+
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire } from "@modern-js/utils";
|
|
7
7
|
function getHtmlTemplates(pwd, routes) {
|
|
8
8
|
return _getHtmlTemplates.apply(this, arguments);
|
|
9
9
|
}
|
|
@@ -180,7 +180,7 @@ function _getServerManifest() {
|
|
|
180
180
|
return Boolean(route.bundle);
|
|
181
181
|
}).map(function() {
|
|
182
182
|
var _ref = _async_to_generator(function(route) {
|
|
183
|
-
var entryName, renderBundlePath, loaderBundlePath, renderBundle, loaderBundle;
|
|
183
|
+
var entryName, renderBundlePath, loaderBundlePath, renderBundle, loaderBundle, _tmp, _tmp1;
|
|
184
184
|
return _ts_generator(this, function(_state2) {
|
|
185
185
|
switch (_state2.label) {
|
|
186
186
|
case 0:
|
|
@@ -200,7 +200,35 @@ function _getServerManifest() {
|
|
|
200
200
|
case 2:
|
|
201
201
|
loaderBundle = _state2.sent();
|
|
202
202
|
renderBundle && (renderBundles[entryName] = renderBundle);
|
|
203
|
-
|
|
203
|
+
_tmp = loaderBundle;
|
|
204
|
+
if (!_tmp)
|
|
205
|
+
return [
|
|
206
|
+
3,
|
|
207
|
+
6
|
|
208
|
+
];
|
|
209
|
+
if (!(loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules))
|
|
210
|
+
return [
|
|
211
|
+
3,
|
|
212
|
+
4
|
|
213
|
+
];
|
|
214
|
+
return [
|
|
215
|
+
4,
|
|
216
|
+
loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules()
|
|
217
|
+
];
|
|
218
|
+
case 3:
|
|
219
|
+
_tmp1 = _state2.sent();
|
|
220
|
+
return [
|
|
221
|
+
3,
|
|
222
|
+
5
|
|
223
|
+
];
|
|
224
|
+
case 4:
|
|
225
|
+
_tmp1 = loaderBundle;
|
|
226
|
+
_state2.label = 5;
|
|
227
|
+
case 5:
|
|
228
|
+
_tmp = loaderBundles[entryName] = _tmp1;
|
|
229
|
+
_state2.label = 6;
|
|
230
|
+
case 6:
|
|
231
|
+
_tmp;
|
|
204
232
|
return [
|
|
205
233
|
2
|
|
206
234
|
];
|
|
@@ -3,9 +3,9 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "path";
|
|
6
|
+
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
6
7
|
import { fs } from "@modern-js/utils";
|
|
7
8
|
import { getMimeType } from "hono/utils/mime";
|
|
8
|
-
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
9
9
|
import { sortRoutes } from "../../../utils";
|
|
10
10
|
var serverStaticPlugin = function() {
|
|
11
11
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { FormData as NodeFormData, Headers as NodeHeaders, Request as NodeRequest, Response as NodeResponse } from "@web-std/fetch";
|
|
2
|
+
import { Blob as NodeBlob, File as NodeFile } from "@web-std/file";
|
|
3
|
+
import { ReadableStream as NodeReadableStream, TransformStream as NodeTransformStream, WritableStream as NodeWritableStream } from "@web-std/stream";
|
|
4
4
|
if (!Object.getOwnPropertyDescriptor(NodeHeaders.prototype, "getSetCookie")) {
|
|
5
5
|
Object.defineProperty(NodeHeaders.prototype, "getSetCookie", {
|
|
6
6
|
value: function getSetCookie() {
|
|
@@ -3,6 +3,7 @@ import { _ as _class_private_field_get } from "@swc/helpers/_/_class_private_fie
|
|
|
3
3
|
import { _ as _class_private_field_init } from "@swc/helpers/_/_class_private_field_init";
|
|
4
4
|
import { _ as _class_private_field_set } from "@swc/helpers/_/_class_private_field_set";
|
|
5
5
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
6
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
7
|
import { getCookie } from "hono/cookie";
|
|
7
8
|
import { getHost } from "../../utils";
|
|
8
9
|
function createBaseHookContext(c, resParams) {
|
|
@@ -59,7 +60,12 @@ var BaseHookRequest = /* @__PURE__ */ function() {
|
|
|
59
60
|
{
|
|
60
61
|
key: "url",
|
|
61
62
|
get: function get() {
|
|
62
|
-
|
|
63
|
+
var query = _class_private_field_get(this, _c).req.query();
|
|
64
|
+
var q = Object.entries(query).map(function(param) {
|
|
65
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
66
|
+
return "".concat(key, "=").concat(value);
|
|
67
|
+
}).join("&");
|
|
68
|
+
return q ? "".concat(_class_private_field_get(this, _c).req.path, "?").concat(q) : _class_private_field_get(this, _c).req.path;
|
|
63
69
|
},
|
|
64
70
|
set: (
|
|
65
71
|
// TODO: remove next major version
|
|
@@ -2,9 +2,9 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
import { createBaseHookContext } from "./base";
|
|
5
6
|
import { RouterAPI } from "./routerApi";
|
|
6
7
|
import { TemplateApi } from "./template";
|
|
7
|
-
import { createBaseHookContext } from "./base";
|
|
8
8
|
function getAfterMatchCtx(entryName, baseHookCtx) {
|
|
9
9
|
var afterMatchCtx = baseHookCtx;
|
|
10
10
|
afterMatchCtx.router = new RouterAPI(entryName);
|
|
@@ -2,11 +2,11 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
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
|
-
import { transformResponse } from "../../utils";
|
|
6
|
-
import { getLoaderCtx } from "../../helper";
|
|
7
5
|
import { ServerTimings } from "../../constants";
|
|
8
|
-
import {
|
|
6
|
+
import { getLoaderCtx } from "../../helper";
|
|
7
|
+
import { transformResponse } from "../../utils";
|
|
9
8
|
import { createBaseHookContext } from "./base";
|
|
9
|
+
import { createAfterStreamingRenderContext, createCustomMiddlewaresCtx, getAfterMatchCtx, getAfterRenderCtx } from "./context";
|
|
10
10
|
var noop = function() {
|
|
11
11
|
};
|
|
12
12
|
var isHtmlResponse = function(response) {
|
|
@@ -36,7 +36,7 @@ var CustomServer = /* @__PURE__ */ function() {
|
|
|
36
36
|
var _this = this;
|
|
37
37
|
return function() {
|
|
38
38
|
var _ref = _async_to_generator(function(c, next) {
|
|
39
|
-
var routeInfo, monitors, baseHookCtx, afterMatchCtx, getCost, cost, _afterMatchCtx_router, url, status, current, rewriteRoute,
|
|
39
|
+
var routeInfo, monitors, baseHookCtx, afterMatchCtx, getCost, cost, _afterMatchCtx_router, url, status, current, rewriteRoute, afterStreamingRenderContext, afterRenderCtx, getCost1, cost1, newBody;
|
|
40
40
|
return _ts_generator(this, function(_state) {
|
|
41
41
|
switch (_state.label) {
|
|
42
42
|
case 0:
|
|
@@ -70,17 +70,7 @@ var CustomServer = /* @__PURE__ */ function() {
|
|
|
70
70
|
return route.entryName === current;
|
|
71
71
|
});
|
|
72
72
|
if (rewriteRoute) {
|
|
73
|
-
|
|
74
|
-
url1 = new URL(c.req.url);
|
|
75
|
-
newUrl = new URL(rewriteRoute.urlPath, url1.origin);
|
|
76
|
-
return [
|
|
77
|
-
2,
|
|
78
|
-
_this.serverBase.request(newUrl, {
|
|
79
|
-
headers,
|
|
80
|
-
method,
|
|
81
|
-
signal
|
|
82
|
-
}, c.env)
|
|
83
|
-
];
|
|
73
|
+
c.set("matchPathname", rewriteRoute.urlPath);
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
76
|
if (c.finalized) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { injectRenderHandlerPlugin } from "./render";
|
|
2
|
-
import { initMonitorsPlugin, injectloggerPluigin, injectServerTiming } from "./monitors";
|
|
3
|
-
import { processedByPlugin } from "./processedBy";
|
|
4
1
|
import { logPlugin } from "./log";
|
|
2
|
+
import { initMonitorsPlugin, injectServerTiming, injectloggerPluigin } from "./monitors";
|
|
3
|
+
import { processedByPlugin } from "./processedBy";
|
|
4
|
+
import { injectRenderHandlerPlugin } from "./render";
|
|
5
5
|
function createDefaultPlugins() {
|
|
6
6
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
7
7
|
var plugins = [
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
|
|
4
|
-
import {
|
|
4
|
+
import { getLoaderCtx } from "../../helper";
|
|
5
5
|
import { sortRoutes } from "../../utils";
|
|
6
6
|
import { CustomServer, getServerMidFromUnstableMid } from "../customServer";
|
|
7
|
-
import {
|
|
7
|
+
import { initReporter } from "../monitors";
|
|
8
8
|
export * from "./inject";
|
|
9
9
|
var renderPlugin = function() {
|
|
10
10
|
return {
|
|
@@ -136,7 +136,7 @@ function getPageRoutes(routes) {
|
|
|
136
136
|
function createRenderHandler(render) {
|
|
137
137
|
return function() {
|
|
138
138
|
var _ref = _async_to_generator(function(c, _) {
|
|
139
|
-
var _c_env_node, logger, reporter, monitors, templates, serverManifest, locals, metrics, loaderContext, request, nodeReq, res, body, status, headers, headersData;
|
|
139
|
+
var _c_env_node, logger, reporter, monitors, templates, serverManifest, locals, metrics, matchPathname, loaderContext, request, nodeReq, res, body, status, headers, headersData;
|
|
140
140
|
return _ts_generator(this, function(_state) {
|
|
141
141
|
switch (_state.label) {
|
|
142
142
|
case 0:
|
|
@@ -147,6 +147,7 @@ function createRenderHandler(render) {
|
|
|
147
147
|
serverManifest = c.get("serverManifest") || {};
|
|
148
148
|
locals = c.get("locals");
|
|
149
149
|
metrics = c.get("metrics");
|
|
150
|
+
matchPathname = c.get("matchPathname");
|
|
150
151
|
loaderContext = getLoaderCtx(c);
|
|
151
152
|
request = c.req.raw;
|
|
152
153
|
nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
|
|
@@ -161,7 +162,8 @@ function createRenderHandler(render) {
|
|
|
161
162
|
metrics,
|
|
162
163
|
serverManifest,
|
|
163
164
|
loaderContext,
|
|
164
|
-
locals
|
|
165
|
+
locals,
|
|
166
|
+
matchPathname
|
|
165
167
|
})
|
|
166
168
|
];
|
|
167
169
|
case 1:
|