@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
|
@@ -6,13 +6,13 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
6
6
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
7
7
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
8
8
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
9
|
+
import { compatibleRequire } from "@modern-js/utils";
|
|
9
10
|
import { cutNameByHyphen } from "@modern-js/utils/universal";
|
|
10
11
|
import { TrieRouter } from "hono/router/trie-router";
|
|
11
|
-
import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse, onError as onErrorFn, ErrorDigest, parseHeaders } from "../../utils";
|
|
12
12
|
import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
|
|
13
|
+
import { ErrorDigest, createErrorHtml, getPathname, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes, transformResponse } from "../../utils";
|
|
13
14
|
import { dataHandler } from "./dataHandler";
|
|
14
15
|
import { ssrRender } from "./ssrRender";
|
|
15
|
-
import { compatibleRequire } from "@modern-js/utils";
|
|
16
16
|
var DYNAMIC_ROUTE_REG = /\/:./;
|
|
17
17
|
function getRouter(routes) {
|
|
18
18
|
var dynamicRoutes = [];
|
|
@@ -50,8 +50,7 @@ function getRouter(routes) {
|
|
|
50
50
|
}
|
|
51
51
|
return router;
|
|
52
52
|
}
|
|
53
|
-
function matchRoute(router,
|
|
54
|
-
var pathname = getPathname(request);
|
|
53
|
+
function matchRoute(router, pathname) {
|
|
55
54
|
var matched = router.match("*", pathname);
|
|
56
55
|
var result = matched[0][0];
|
|
57
56
|
return result || [];
|
|
@@ -76,12 +75,13 @@ function _createRender() {
|
|
|
76
75
|
2,
|
|
77
76
|
function() {
|
|
78
77
|
var _ref = _async_to_generator(function(req, param2) {
|
|
79
|
-
var logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, loaderContext, _matchRoute, routeInfo, params, onFallback, html, renderMode, pathname, headerData, onError, onTiming, onBoundError, renderOptions, response, _tmp;
|
|
78
|
+
var logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext, forMatchpathname, _matchRoute, routeInfo, params, onFallback, html, renderMode, pathname, headerData, onError, onTiming, onBoundError, renderOptions, response, _tmp;
|
|
80
79
|
return _ts_generator(this, function(_state2) {
|
|
81
80
|
switch (_state2.label) {
|
|
82
81
|
case 0:
|
|
83
|
-
logger = param2.logger, reporter = param2.reporter, metrics = param2.metrics, monitors = param2.monitors, nodeReq = param2.nodeReq, templates = param2.templates, serverManifest = param2.serverManifest, locals = param2.locals, loaderContext = param2.loaderContext;
|
|
84
|
-
|
|
82
|
+
logger = param2.logger, reporter = param2.reporter, metrics = param2.metrics, monitors = param2.monitors, nodeReq = param2.nodeReq, templates = param2.templates, serverManifest = param2.serverManifest, locals = param2.locals, matchPathname = param2.matchPathname, loaderContext = param2.loaderContext;
|
|
83
|
+
forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : getPathname(req);
|
|
84
|
+
_matchRoute = _sliced_to_array(matchRoute(router, forMatchpathname), 2), routeInfo = _matchRoute[0], params = _matchRoute[1];
|
|
85
85
|
onFallback = function() {
|
|
86
86
|
var _ref2 = _async_to_generator(function(reason, error) {
|
|
87
87
|
return _ts_generator(this, function(_state3) {
|
|
@@ -131,7 +131,7 @@ function _createRender() {
|
|
|
131
131
|
pathname = getPathname(req);
|
|
132
132
|
headerData = parseHeaders(req);
|
|
133
133
|
onError = function(e) {
|
|
134
|
-
monitors === null || monitors === void 0 ? void 0 : monitors.error("SSR Error - ".concat(_instanceof(e, Error) ? e.name : e, ", error = %s, req.url = %s, req.headers = %o"), _instanceof(e, Error) ? e.stack || e.message : e,
|
|
134
|
+
monitors === null || monitors === void 0 ? void 0 : monitors.error("SSR Error - ".concat(_instanceof(e, Error) ? e.name : e, ", error = %s, req.url = %s, req.headers = %o"), _instanceof(e, Error) ? e.stack || e.message : e, forMatchpathname, getHeadersWithoutCookie(headerData));
|
|
135
135
|
};
|
|
136
136
|
onTiming = function(name, dur) {
|
|
137
137
|
monitors === null || monitors === void 0 ? void 0 : monitors.timing(name, dur, "SSR");
|
|
@@ -353,11 +353,7 @@ function _renderHandler() {
|
|
|
353
353
|
response = csrRender(options.html);
|
|
354
354
|
_state.label = 9;
|
|
355
355
|
case 9:
|
|
356
|
-
|
|
357
|
-
newRes = transformResponse(response, injectServerData(serverData));
|
|
358
|
-
} else {
|
|
359
|
-
newRes = response;
|
|
360
|
-
}
|
|
356
|
+
newRes = transformResponse(response, injectServerData(serverData));
|
|
361
357
|
routeInfo = options.routeInfo;
|
|
362
358
|
applyExtendHeaders(newRes, routeInfo);
|
|
363
359
|
return [
|
|
@@ -2,9 +2,9 @@ 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 { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
|
|
5
|
-
import { parseHeaders, getPathname } from "../../utils";
|
|
6
5
|
import { X_MODERNJS_RENDER } from "../../constants";
|
|
7
|
-
import {
|
|
6
|
+
import { getPathname, parseHeaders } from "../../utils";
|
|
7
|
+
import { getCacheResult, matchCacheControl } from "./ssrCache";
|
|
8
8
|
var SERVER_RUNTIME_ENTRY = "requestHandler";
|
|
9
9
|
function ssrRender(request, _) {
|
|
10
10
|
return _ssrRender.apply(this, arguments);
|
package/dist/esm/serverBase.js
CHANGED
|
@@ -5,8 +5,8 @@ import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_m
|
|
|
5
5
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
6
6
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
7
7
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
8
|
-
import { Hono } from "hono";
|
|
9
8
|
import { createContext } from "@modern-js/plugin";
|
|
9
|
+
import { Hono } from "hono";
|
|
10
10
|
import { PluginManager } from "./pluginManager";
|
|
11
11
|
var _getAppContext = /* @__PURE__ */ new WeakSet(), _applyMiddlewares = /* @__PURE__ */ new WeakSet();
|
|
12
12
|
var ServerBase = /* @__PURE__ */ function() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, DEFAULT_SERVER_CONFIG,
|
|
2
|
+
import { fs, DEFAULT_SERVER_CONFIG, OUTPUT_CONFIG_FILE, lodash as _, compatibleRequire, ensureAbsolutePath, requireExistModule } from "@modern-js/utils";
|
|
3
3
|
import { parse } from "flatted";
|
|
4
4
|
const requireConfig = async (serverConfigPath) => {
|
|
5
5
|
if (fs.pathExistsSync(serverConfigPath)) {
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
const httpCallBack2HonoMid = (handler) => {
|
|
2
2
|
return async (context, next) => {
|
|
3
3
|
const { req, res } = context.env.node;
|
|
4
|
+
const onPipe = () => {
|
|
5
|
+
res._modernBodyPiped = true;
|
|
6
|
+
};
|
|
7
|
+
res.once("pipe", onPipe);
|
|
4
8
|
req.__honoRequest = context.req;
|
|
5
9
|
req.__templates = context.get("templates") || {};
|
|
6
10
|
req.__serverManifest = context.get("serverManifest") || {};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
try {
|
|
12
|
+
await handler(req, res);
|
|
13
|
+
} finally {
|
|
14
|
+
delete req.__honoRequest;
|
|
15
|
+
delete req.__templates;
|
|
16
|
+
delete req.__serverManifest;
|
|
17
|
+
res.removeListener("pipe", onPipe);
|
|
18
|
+
}
|
|
19
|
+
if (res.headersSent || res._modernBodyPiped) {
|
|
13
20
|
context.finalized = true;
|
|
14
21
|
} else {
|
|
15
22
|
await next();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServerResponse } from "node:http";
|
|
2
|
-
import { createReadableStreamFromReadable, writeReadableStreamToWritable } from "./polyfills/stream";
|
|
3
2
|
import { installGlobals } from "./polyfills/install";
|
|
3
|
+
import { createReadableStreamFromReadable, writeReadableStreamToWritable } from "./polyfills/stream";
|
|
4
4
|
import { writeReadableStreamToWritable as writeReadableStreamToWritable2 } from "./polyfills";
|
|
5
5
|
installGlobals();
|
|
6
6
|
const createWebRequest = (req, res, body) => {
|
|
@@ -80,7 +80,7 @@ const getRequestListener = (handler) => {
|
|
|
80
80
|
res
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
if (!res.headersSent && !response.res) {
|
|
83
|
+
if (!res.headersSent && !response.res && !res._modernBodyPiped) {
|
|
84
84
|
await sendResponse(response, res);
|
|
85
85
|
}
|
|
86
86
|
} catch (error) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
3
|
-
import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY,
|
|
3
|
+
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire } from "@modern-js/utils";
|
|
4
4
|
async function getHtmlTemplates(pwd, routes) {
|
|
5
5
|
const htmls = await Promise.all(routes.map(async (route) => {
|
|
6
6
|
let html;
|
|
@@ -49,7 +49,7 @@ async function getServerManifest(pwd, routes, logger) {
|
|
|
49
49
|
const renderBundle = await loadBundle(renderBundlePath, logger);
|
|
50
50
|
const loaderBundle = await loadBundle(loaderBundlePath, logger);
|
|
51
51
|
renderBundle && (renderBundles[entryName] = renderBundle);
|
|
52
|
-
loaderBundle && (loaderBundles[entryName] = loaderBundle);
|
|
52
|
+
loaderBundle && (loaderBundles[entryName] = (loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules) ? await (loaderBundle === null || loaderBundle === void 0 ? void 0 : loaderBundle.loadModules()) : loaderBundle);
|
|
53
53
|
}));
|
|
54
54
|
const loadableUri = path.join(pwd, LOADABLE_STATS_FILE);
|
|
55
55
|
const loadableStats = await compatibleRequire(loadableUri).catch((_) => ({}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
2
3
|
import { fs } from "@modern-js/utils";
|
|
3
4
|
import { getMimeType } from "hono/utils/mime";
|
|
4
|
-
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
5
5
|
import { sortRoutes } from "../../../utils";
|
|
6
6
|
const serverStaticPlugin = () => ({
|
|
7
7
|
name: "@modern-js/plugin-server-static",
|
|
@@ -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() {
|
|
@@ -16,7 +16,9 @@ function createBaseHookContext(c, resParams) {
|
|
|
16
16
|
var _req = /* @__PURE__ */ new WeakMap(), _c = /* @__PURE__ */ new WeakMap(), _headersData = /* @__PURE__ */ new WeakMap(), _headers = /* @__PURE__ */ new WeakMap();
|
|
17
17
|
class BaseHookRequest {
|
|
18
18
|
get url() {
|
|
19
|
-
|
|
19
|
+
const query = _class_private_field_get(this, _c).req.query();
|
|
20
|
+
const q = Object.entries(query).map(([key, value]) => `${key}=${value}`).join("&");
|
|
21
|
+
return q ? `${_class_private_field_get(this, _c).req.path}?${q}` : _class_private_field_get(this, _c).req.path;
|
|
20
22
|
}
|
|
21
23
|
// TODO: remove next major version
|
|
22
24
|
set url(_u) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { createBaseHookContext } from "./base";
|
|
1
2
|
import { RouterAPI } from "./routerApi";
|
|
2
3
|
import { TemplateApi } from "./template";
|
|
3
|
-
import { createBaseHookContext } from "./base";
|
|
4
4
|
function getAfterMatchCtx(entryName, baseHookCtx) {
|
|
5
5
|
const afterMatchCtx = baseHookCtx;
|
|
6
6
|
afterMatchCtx.router = new RouterAPI(entryName);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { time } from "@modern-js/runtime-utils/time";
|
|
2
|
-
import { transformResponse } from "../../utils";
|
|
3
|
-
import { getLoaderCtx } from "../../helper";
|
|
4
2
|
import { ServerTimings } from "../../constants";
|
|
5
|
-
import {
|
|
3
|
+
import { getLoaderCtx } from "../../helper";
|
|
4
|
+
import { transformResponse } from "../../utils";
|
|
6
5
|
import { createBaseHookContext } from "./base";
|
|
6
|
+
import { createAfterStreamingRenderContext, createCustomMiddlewaresCtx, getAfterMatchCtx, getAfterRenderCtx } from "./context";
|
|
7
7
|
const noop = () => {
|
|
8
8
|
};
|
|
9
9
|
const isHtmlResponse = (response) => {
|
|
@@ -31,14 +31,7 @@ class CustomServer {
|
|
|
31
31
|
if (current !== entryName) {
|
|
32
32
|
const rewriteRoute = routes.find((route) => route.entryName === current);
|
|
33
33
|
if (rewriteRoute) {
|
|
34
|
-
|
|
35
|
-
const url2 = new URL(c.req.url);
|
|
36
|
-
const newUrl = new URL(rewriteRoute.urlPath, url2.origin);
|
|
37
|
-
return this.serverBase.request(newUrl, {
|
|
38
|
-
headers,
|
|
39
|
-
method,
|
|
40
|
-
signal
|
|
41
|
-
}, c.env);
|
|
34
|
+
c.set("matchPathname", rewriteRoute.urlPath);
|
|
42
35
|
}
|
|
43
36
|
}
|
|
44
37
|
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(options = {}) {
|
|
6
6
|
const plugins = [
|
|
7
7
|
initMonitorsPlugin(),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
|
|
2
|
-
import {
|
|
2
|
+
import { getLoaderCtx } from "../../helper";
|
|
3
3
|
import { sortRoutes } from "../../utils";
|
|
4
4
|
import { CustomServer, getServerMidFromUnstableMid } from "../customServer";
|
|
5
|
-
import {
|
|
5
|
+
import { initReporter } from "../monitors";
|
|
6
6
|
export * from "./inject";
|
|
7
7
|
const renderPlugin = () => ({
|
|
8
8
|
name: "@modern-js/plugin-render",
|
|
@@ -61,6 +61,7 @@ function createRenderHandler(render) {
|
|
|
61
61
|
const serverManifest = c.get("serverManifest") || {};
|
|
62
62
|
const locals = c.get("locals");
|
|
63
63
|
const metrics = c.get("metrics");
|
|
64
|
+
const matchPathname = c.get("matchPathname");
|
|
64
65
|
const loaderContext = getLoaderCtx(c);
|
|
65
66
|
const request = c.req.raw;
|
|
66
67
|
const nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
|
|
@@ -73,7 +74,8 @@ function createRenderHandler(render) {
|
|
|
73
74
|
metrics,
|
|
74
75
|
serverManifest,
|
|
75
76
|
loaderContext,
|
|
76
|
-
locals
|
|
77
|
+
locals,
|
|
78
|
+
matchPathname
|
|
77
79
|
});
|
|
78
80
|
const { body, status, headers } = res;
|
|
79
81
|
const headersData = {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { compatibleRequire } from "@modern-js/utils";
|
|
1
2
|
import { cutNameByHyphen } from "@modern-js/utils/universal";
|
|
2
3
|
import { TrieRouter } from "hono/router/trie-router";
|
|
3
|
-
import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse, onError as onErrorFn, ErrorDigest, parseHeaders } from "../../utils";
|
|
4
4
|
import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
|
|
5
|
+
import { ErrorDigest, createErrorHtml, getPathname, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes, transformResponse } from "../../utils";
|
|
5
6
|
import { dataHandler } from "./dataHandler";
|
|
6
7
|
import { ssrRender } from "./ssrRender";
|
|
7
|
-
import { compatibleRequire } from "@modern-js/utils";
|
|
8
8
|
const DYNAMIC_ROUTE_REG = /\/:./;
|
|
9
9
|
function getRouter(routes) {
|
|
10
10
|
const dynamicRoutes = [];
|
|
@@ -28,8 +28,7 @@ function getRouter(routes) {
|
|
|
28
28
|
}
|
|
29
29
|
return router;
|
|
30
30
|
}
|
|
31
|
-
function matchRoute(router,
|
|
32
|
-
const pathname = getPathname(request);
|
|
31
|
+
function matchRoute(router, pathname) {
|
|
33
32
|
const matched = router.match("*", pathname);
|
|
34
33
|
const result = matched[0][0];
|
|
35
34
|
return result || [];
|
|
@@ -44,8 +43,9 @@ function getHeadersWithoutCookie(headers) {
|
|
|
44
43
|
}
|
|
45
44
|
async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, config, onFallback: onFallbackFn }) {
|
|
46
45
|
const router = getRouter(routes);
|
|
47
|
-
return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, loaderContext }) => {
|
|
48
|
-
const
|
|
46
|
+
return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext }) => {
|
|
47
|
+
const forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : getPathname(req);
|
|
48
|
+
const [routeInfo, params] = matchRoute(router, forMatchpathname);
|
|
49
49
|
const onFallback = async (reason, error) => {
|
|
50
50
|
return onFallbackFn === null || onFallbackFn === void 0 ? void 0 : onFallbackFn(reason, {
|
|
51
51
|
logger,
|
|
@@ -74,7 +74,7 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
74
74
|
const pathname = getPathname(req);
|
|
75
75
|
const headerData = parseHeaders(req);
|
|
76
76
|
const onError = (e) => {
|
|
77
|
-
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,
|
|
77
|
+
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));
|
|
78
78
|
};
|
|
79
79
|
const onTiming = (name, dur) => {
|
|
80
80
|
monitors === null || monitors === void 0 ? void 0 : monitors.timing(name, dur, "SSR");
|
|
@@ -156,12 +156,7 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
156
156
|
} else {
|
|
157
157
|
response = csrRender(options.html);
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
if (!options.staticGenerate) {
|
|
161
|
-
newRes = transformResponse(response, injectServerData(serverData));
|
|
162
|
-
} else {
|
|
163
|
-
newRes = response;
|
|
164
|
-
}
|
|
159
|
+
const newRes = transformResponse(response, injectServerData(serverData));
|
|
165
160
|
const { routeInfo } = options;
|
|
166
161
|
applyExtendHeaders(newRes, routeInfo);
|
|
167
162
|
return newRes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
|
|
2
|
-
import { parseHeaders, getPathname } from "../../utils";
|
|
3
2
|
import { X_MODERNJS_RENDER } from "../../constants";
|
|
4
|
-
import {
|
|
3
|
+
import { getPathname, parseHeaders } from "../../utils";
|
|
4
|
+
import { getCacheResult, matchCacheControl } from "./ssrCache";
|
|
5
5
|
const SERVER_RUNTIME_ENTRY = "requestHandler";
|
|
6
6
|
async function ssrRender(request, { routeInfo, html, config: userConfig, staticGenerate, nodeReq, serverManifest, locals, params, loaderContext, reporter, cacheConfig, logger, metrics, onError, onTiming }) {
|
|
7
7
|
var _serverManifest_renderBundles;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _class_private_method_get } from "@swc/helpers/_/_class_private_method_get";
|
|
2
2
|
import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_method_init";
|
|
3
|
-
import { Hono } from "hono";
|
|
4
3
|
import { createContext } from "@modern-js/plugin";
|
|
4
|
+
import { Hono } from "hono";
|
|
5
5
|
import { PluginManager } from "./pluginManager";
|
|
6
6
|
var _getAppContext = /* @__PURE__ */ new WeakSet(), _applyMiddlewares = /* @__PURE__ */ new WeakSet();
|
|
7
7
|
class ServerBase {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Context, HonoRequest, Middleware, Next, NodeRequest, NodeResponse, ServerEnv, ServerManifest } from '../../types';
|
|
2
2
|
type NodeBindings = {
|
|
3
3
|
node: {
|
|
4
4
|
req: NodeRequest & {
|
|
@@ -6,7 +6,9 @@ type NodeBindings = {
|
|
|
6
6
|
__templates?: Record<string, string>;
|
|
7
7
|
__serverManifest?: ServerManifest;
|
|
8
8
|
};
|
|
9
|
-
res: NodeResponse
|
|
9
|
+
res: NodeResponse & {
|
|
10
|
+
_modernBodyPiped?: boolean;
|
|
11
|
+
};
|
|
10
12
|
};
|
|
11
13
|
};
|
|
12
14
|
export type ServerNodeEnv = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ServerRoute } from '@modern-js/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { HtmlNormalizedConfig, Middleware, OutputNormalizedConfig, ServerPlugin } from '../../../types';
|
|
3
3
|
export declare const serverStaticPlugin: () => ServerPlugin;
|
|
4
4
|
export type PublicMiddlwareOptions = {
|
|
5
5
|
pwd: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AfterMatchContext, AfterRenderContext,
|
|
2
|
-
import type { Context, ServerEnv } from '../../types';
|
|
1
|
+
import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, HookContext, MiddlewareContext, ServerRoute } from '@modern-js/types';
|
|
3
2
|
import type { ServerNodeEnv } from '../../adapters/node/hono';
|
|
3
|
+
import type { Context, ServerEnv } from '../../types';
|
|
4
4
|
import { type ResArgs } from './base';
|
|
5
5
|
export declare function getAfterMatchCtx(entryName: string, baseHookCtx: HookContext): AfterMatchContext;
|
|
6
6
|
export declare function getAfterRenderCtx(c: Context, baseHookCtx: HookContext, route: Partial<ServerRoute>): Promise<AfterRenderContext>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ServerRoute, UnstableMiddleware } from '@modern-js/types';
|
|
2
|
-
import type { ServerBase } from '../../serverBase';
|
|
3
|
-
import type { ServerHookRunner, Middleware, ServerEnv } from '../../types';
|
|
4
2
|
import type { ServerNodeEnv } from '../../adapters/node/hono';
|
|
3
|
+
import type { ServerBase } from '../../serverBase';
|
|
4
|
+
import type { Middleware, ServerEnv, ServerHookRunner } from '../../types';
|
|
5
5
|
export declare class CustomServer {
|
|
6
6
|
private runner;
|
|
7
7
|
private serverMiddlewarePromise;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { IncomingMessage } from 'http';
|
|
3
|
-
import type {
|
|
4
|
-
import type { OnError, OnTiming, Params } from '../../types/requestHandler';
|
|
3
|
+
import type { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
|
|
5
4
|
import type { CacheConfig, ServerManifest, UserConfig } from '../../types';
|
|
5
|
+
import type { OnError, OnTiming, Params } from '../../types/requestHandler';
|
|
6
6
|
export interface SSRRenderOptions {
|
|
7
7
|
pwd: string;
|
|
8
8
|
html: string;
|
|
@@ -6,32 +6,9 @@ type Route = string | string[] | {
|
|
|
6
6
|
resHeaders?: Record<string, unknown>;
|
|
7
7
|
};
|
|
8
8
|
export type Routes = Record<string, Route>;
|
|
9
|
-
type PreloadLink = {
|
|
10
|
-
url: string;
|
|
11
|
-
as?: string;
|
|
12
|
-
rel?: string;
|
|
13
|
-
};
|
|
14
|
-
type PreloadInclude = Array<string | PreloadLink>;
|
|
15
|
-
interface PreloadAttributes {
|
|
16
|
-
script?: Record<string, boolean | string>;
|
|
17
|
-
style?: Record<string, boolean | string>;
|
|
18
|
-
image?: Record<string, boolean | string>;
|
|
19
|
-
font?: Record<string, boolean | string>;
|
|
20
|
-
}
|
|
21
|
-
export type SSRPreload = {
|
|
22
|
-
/** Include external preload links to enhance the page's performance by preloading additional resources. */
|
|
23
|
-
include?: PreloadInclude;
|
|
24
|
-
/** Utilize string matching to exclude specific preload links. */
|
|
25
|
-
exclude?: RegExp | string;
|
|
26
|
-
/** Disable preload when the User-Agent is matched. */
|
|
27
|
-
userAgentFilter?: RegExp | string;
|
|
28
|
-
/** Include additional attributes to the Header Link. */
|
|
29
|
-
attributes?: PreloadAttributes;
|
|
30
|
-
};
|
|
31
9
|
export type SSR = boolean | {
|
|
32
10
|
forceCSR?: boolean;
|
|
33
11
|
mode?: SSRMode;
|
|
34
|
-
preload?: boolean | SSRPreload;
|
|
35
12
|
inlineScript?: boolean;
|
|
36
13
|
disablePrerender?: boolean;
|
|
37
14
|
unsafeHeaders?: string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/** Hooks */
|
|
3
|
-
import type { Server as NodeServer,
|
|
4
|
-
import type {
|
|
3
|
+
import type { IncomingMessage, Server as NodeServer, ServerResponse } from 'http';
|
|
4
|
+
import type { AsyncPipeline, AsyncSetup, AsyncWaterfall, CommonAPI, ParallelWorkflow, PluginOptions, ToRunners, ToThreads, createContext } from '@modern-js/plugin';
|
|
5
5
|
import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, CacheOption, Container, HttpMethodDecider, ISAppContext, Logger, Metrics, MiddlewareContext, Reporter, ServerRoute, UnstableMiddleware } from '@modern-js/types';
|
|
6
6
|
import type { MiddlewareHandler } from 'hono';
|
|
7
7
|
import type { UserConfig } from './config';
|
|
@@ -14,6 +14,8 @@ export interface RenderOptions {
|
|
|
14
14
|
metrics?: Metrics;
|
|
15
15
|
/** @deprecated */
|
|
16
16
|
reporter?: Reporter;
|
|
17
|
+
/** For compat rewrite MPA, while not modify request */
|
|
18
|
+
matchPathname?: string;
|
|
17
19
|
monitors?: Monitors;
|
|
18
20
|
serverManifest: ServerManifest;
|
|
19
21
|
nodeReq?: IncomingMessage;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Metrics, Reporter, ServerRoute
|
|
1
|
+
import type { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
|
|
2
2
|
import type { ServerUserConfig } from './config';
|
|
3
3
|
export type Resource = {
|
|
4
4
|
loadableStats: Record<string, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Readable } from 'node:stream';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BaseSSRServerContext, Logger, Metrics, Monitors, NestedRoute, Reporter, ServerRoute } from '@modern-js/types';
|
|
4
4
|
import type { RequestHandler as BundleRequestHandler, OnError, OnTiming } from './requestHandler';
|
|
5
5
|
export type SSRServerContext = BaseSSRServerContext & {
|
|
6
6
|
staticGenerate?: boolean;
|
|
@@ -40,6 +40,7 @@ type ServerVariables = {
|
|
|
40
40
|
monitors: Monitors;
|
|
41
41
|
serverManifest?: ServerManifest;
|
|
42
42
|
templates?: Record<string, string>;
|
|
43
|
+
matchPathname?: string;
|
|
43
44
|
/**
|
|
44
45
|
* Communicating with custom server hook & modern ssrContext.
|
|
45
46
|
*
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.58.3
|
|
18
|
+
"version": "2.58.3",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"flatted": "^3.2.9",
|
|
54
54
|
"hono": "^3.12.2",
|
|
55
55
|
"ts-deepmerge": "7.0.0",
|
|
56
|
-
"@modern-js/plugin": "2.58.
|
|
57
|
-
"@modern-js/utils": "2.58.
|
|
58
|
-
"@modern-js/
|
|
56
|
+
"@modern-js/plugin": "2.58.3",
|
|
57
|
+
"@modern-js/runtime-utils": "2.58.3",
|
|
58
|
+
"@modern-js/utils": "2.58.3"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/jest": "^29",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"jest": "^29",
|
|
66
66
|
"ts-jest": "^29.1.0",
|
|
67
67
|
"typescript": "^5",
|
|
68
|
-
"@modern-js/types": "2.58.
|
|
69
|
-
"@scripts/build": "2.58.
|
|
70
|
-
"@scripts/jest-config": "2.58.
|
|
68
|
+
"@modern-js/types": "2.58.3",
|
|
69
|
+
"@scripts/build": "2.58.3",
|
|
70
|
+
"@scripts/jest-config": "2.58.3"
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"publishConfig": {
|