@modern-js/server-core 2.58.3-alpha.1 → 2.59.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/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 +6 -22
- package/dist/cjs/plugins/default.js +2 -2
- package/dist/cjs/plugins/render/index.js +5 -3
- package/dist/cjs/plugins/render/inject.js +13 -3
- package/dist/cjs/plugins/render/render.js +21 -19
- package/dist/cjs/plugins/render/ssrRender.js +1 -1
- package/dist/cjs/serverBase.js +2 -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 +8 -17
- package/dist/esm/plugins/default.js +3 -3
- package/dist/esm/plugins/render/index.js +6 -4
- package/dist/esm/plugins/render/inject.js +33 -5
- package/dist/esm/plugins/render/render.js +50 -42
- package/dist/esm/plugins/render/ssrRender.js +2 -2
- package/dist/esm/serverBase.js +2 -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 +6 -12
- 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/inject.js +13 -3
- package/dist/esm-node/plugins/render/render.js +21 -19
- package/dist/esm-node/plugins/render/ssrRender.js +2 -2
- package/dist/esm-node/serverBase.js +2 -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/inject.d.ts +1 -1
- package/dist/types/plugins/render/render.d.ts +2 -7
- 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 +8 -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
|
@@ -7,16 +7,25 @@ const injectRenderHandlerPlugin = ({ staticGenerate, cacheConfig }) => ({
|
|
|
7
7
|
var _config_render;
|
|
8
8
|
const { distDirectory: pwd, routes, metaName } = api.useAppContext();
|
|
9
9
|
const config = api.useConfigContext();
|
|
10
|
+
const hookRunner = api.useHookRunners();
|
|
10
11
|
if (!routes) {
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
14
|
+
const onFallback = async (reason, utils, error) => {
|
|
15
|
+
await hookRunner.fallback({
|
|
16
|
+
reason,
|
|
17
|
+
...utils,
|
|
18
|
+
error
|
|
19
|
+
});
|
|
20
|
+
};
|
|
13
21
|
const getRenderHandlerOptions = {
|
|
14
22
|
pwd,
|
|
15
23
|
routes,
|
|
16
24
|
config,
|
|
17
25
|
metaName,
|
|
18
26
|
cacheConfig: ((_config_render = config.render) === null || _config_render === void 0 ? void 0 : _config_render.cache) || cacheConfig,
|
|
19
|
-
staticGenerate
|
|
27
|
+
staticGenerate,
|
|
28
|
+
onFallback
|
|
20
29
|
};
|
|
21
30
|
const render = await getRenderHandler(getRenderHandlerOptions);
|
|
22
31
|
api.setAppContext({
|
|
@@ -28,7 +37,7 @@ const injectRenderHandlerPlugin = ({ staticGenerate, cacheConfig }) => ({
|
|
|
28
37
|
};
|
|
29
38
|
}
|
|
30
39
|
});
|
|
31
|
-
async function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate }) {
|
|
40
|
+
async function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate, onFallback }) {
|
|
32
41
|
var _config_server, _config_security;
|
|
33
42
|
const ssrConfig = (_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr;
|
|
34
43
|
const forceCSR = typeof ssrConfig === "object" ? ssrConfig.forceCSR : false;
|
|
@@ -40,7 +49,8 @@ async function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, st
|
|
|
40
49
|
cacheConfig,
|
|
41
50
|
forceCSR,
|
|
42
51
|
nonce: (_config_security = config.security) === null || _config_security === void 0 ? void 0 : _config_security.nonce,
|
|
43
|
-
metaName: metaName || "modern-js"
|
|
52
|
+
metaName: metaName || "modern-js",
|
|
53
|
+
onFallback
|
|
44
54
|
});
|
|
45
55
|
return render;
|
|
46
56
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { cutNameByHyphen } from "@modern-js/utils/universal";
|
|
2
2
|
import { TrieRouter } from "hono/router/trie-router";
|
|
3
|
-
import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse, onError as onErrorFn, ErrorDigest, parseHeaders } from "../../utils";
|
|
4
3
|
import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
|
|
4
|
+
import { ErrorDigest, createErrorHtml, getPathname, getRuntimeEnv, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes, transformResponse } from "../../utils";
|
|
5
5
|
import { dataHandler } from "./dataHandler";
|
|
6
6
|
import { ssrRender } from "./ssrRender";
|
|
7
|
-
import { compatibleRequire } from "@modern-js/utils";
|
|
8
7
|
const DYNAMIC_ROUTE_REG = /\/:./;
|
|
9
8
|
function getRouter(routes) {
|
|
10
9
|
const dynamicRoutes = [];
|
|
@@ -28,8 +27,7 @@ function getRouter(routes) {
|
|
|
28
27
|
}
|
|
29
28
|
return router;
|
|
30
29
|
}
|
|
31
|
-
function matchRoute(router,
|
|
32
|
-
const pathname = getPathname(request);
|
|
30
|
+
function matchRoute(router, pathname) {
|
|
33
31
|
const matched = router.match("*", pathname);
|
|
34
32
|
const result = matched[0][0];
|
|
35
33
|
return result || [];
|
|
@@ -44,9 +42,14 @@ function getHeadersWithoutCookie(headers) {
|
|
|
44
42
|
}
|
|
45
43
|
async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, config, onFallback: onFallbackFn }) {
|
|
46
44
|
const router = getRouter(routes);
|
|
47
|
-
return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, loaderContext }) => {
|
|
48
|
-
const
|
|
45
|
+
return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext }) => {
|
|
46
|
+
const forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : getPathname(req);
|
|
47
|
+
const [routeInfo, params] = matchRoute(router, forMatchpathname);
|
|
48
|
+
const framework = metaName || "modern-js";
|
|
49
|
+
const fallbackHeader = `x-${cutNameByHyphen(framework)}-ssr-fallback`;
|
|
50
|
+
let fallbackReason = null;
|
|
49
51
|
const onFallback = async (reason, error) => {
|
|
52
|
+
fallbackReason = reason;
|
|
50
53
|
return onFallbackFn === null || onFallbackFn === void 0 ? void 0 : onFallbackFn(reason, {
|
|
51
54
|
logger,
|
|
52
55
|
reporter,
|
|
@@ -70,11 +73,10 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
70
73
|
}
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
|
-
const renderMode = await getRenderMode(req,
|
|
74
|
-
const pathname = getPathname(req);
|
|
76
|
+
const renderMode = await getRenderMode(req, fallbackHeader, routeInfo.isSSR, forceCSR, nodeReq, onFallback);
|
|
75
77
|
const headerData = parseHeaders(req);
|
|
76
78
|
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,
|
|
79
|
+
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
80
|
};
|
|
79
81
|
const onTiming = (name, dur) => {
|
|
80
82
|
monitors === null || monitors === void 0 ? void 0 : monitors.timing(name, dur, "SSR");
|
|
@@ -114,6 +116,9 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
114
116
|
default:
|
|
115
117
|
throw new Error(`Unknown render mode: ${renderMode}`);
|
|
116
118
|
}
|
|
119
|
+
if (fallbackReason) {
|
|
120
|
+
response.headers.set(fallbackHeader, `1;reason=${fallbackReason}`);
|
|
121
|
+
}
|
|
117
122
|
return response;
|
|
118
123
|
};
|
|
119
124
|
}
|
|
@@ -128,11 +133,14 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
128
133
|
let response = null;
|
|
129
134
|
const { serverManifest } = options;
|
|
130
135
|
const ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
|
|
131
|
-
|
|
136
|
+
const runtimeEnv = getRuntimeEnv();
|
|
137
|
+
if (serverManifest.nestedRoutesJson && ssrByRouteIds && (ssrByRouteIds === null || ssrByRouteIds === void 0 ? void 0 : ssrByRouteIds.length) > 0 && runtimeEnv === "node") {
|
|
132
138
|
const { nestedRoutesJson } = serverManifest;
|
|
133
139
|
const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
|
|
134
140
|
if (routes) {
|
|
135
|
-
const
|
|
141
|
+
const urlPath = "node:url";
|
|
142
|
+
const { pathToFileURL } = await import(urlPath);
|
|
143
|
+
const { matchRoutes } = await import(pathToFileURL(require.resolve("@modern-js/runtime-utils/remix-router")).href);
|
|
136
144
|
const url = new URL(request.url);
|
|
137
145
|
const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
|
|
138
146
|
if (!matchedRoutes) {
|
|
@@ -156,12 +164,7 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
156
164
|
} else {
|
|
157
165
|
response = csrRender(options.html);
|
|
158
166
|
}
|
|
159
|
-
|
|
160
|
-
if (!options.staticGenerate) {
|
|
161
|
-
newRes = transformResponse(response, injectServerData(serverData));
|
|
162
|
-
} else {
|
|
163
|
-
newRes = response;
|
|
164
|
-
}
|
|
167
|
+
const newRes = transformResponse(response, injectServerData(serverData));
|
|
165
168
|
const { routeInfo } = options;
|
|
166
169
|
applyExtendHeaders(newRes, routeInfo);
|
|
167
170
|
return newRes;
|
|
@@ -171,9 +174,8 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
171
174
|
});
|
|
172
175
|
}
|
|
173
176
|
}
|
|
174
|
-
async function getRenderMode(req,
|
|
177
|
+
async function getRenderMode(req, fallbackHeader, isSSR, forceCSR, nodeReq, onFallback) {
|
|
175
178
|
const query = parseQuery(req);
|
|
176
|
-
const fallbackHeader = `x-${cutNameByHyphen(framework)}-ssr-fallback`;
|
|
177
179
|
if (isSSR) {
|
|
178
180
|
if (query.__loader) {
|
|
179
181
|
return "data";
|
|
@@ -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 {
|
|
@@ -76,6 +76,7 @@ function getAppContext() {
|
|
|
76
76
|
middlewares: [],
|
|
77
77
|
appDirectory: (context === null || context === void 0 ? void 0 : context.appDirectory) || "",
|
|
78
78
|
apiDirectory: context === null || context === void 0 ? void 0 : context.apiDirectory,
|
|
79
|
+
internalDirectory: (context === null || context === void 0 ? void 0 : context.internalDirectory) || "",
|
|
79
80
|
lambdaDirectory: context === null || context === void 0 ? void 0 : context.lambdaDirectory,
|
|
80
81
|
sharedDirectory: (context === null || context === void 0 ? void 0 : context.sharedDirectory) || "",
|
|
81
82
|
distDirectory: pwd,
|
|
@@ -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;
|
|
@@ -4,4 +4,4 @@ export interface InjectRenderHandlerOptions {
|
|
|
4
4
|
cacheConfig?: CacheConfig;
|
|
5
5
|
}
|
|
6
6
|
export declare const injectRenderHandlerPlugin: ({ staticGenerate, cacheConfig, }: InjectRenderHandlerOptions) => ServerPlugin;
|
|
7
|
-
export declare function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate, }: GetRenderHandlerOptions): Promise<Render>;
|
|
7
|
+
export declare function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate, onFallback, }: GetRenderHandlerOptions): Promise<Render>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CacheConfig,
|
|
1
|
+
import type { ServerRoute } from '@modern-js/types';
|
|
2
|
+
import type { CacheConfig, OnFallback, UserConfig } from '../../types';
|
|
3
3
|
import type { Render } from '../../types';
|
|
4
|
-
export type OnFallback = (reason: FallbackReason, utils: {
|
|
5
|
-
logger: Logger;
|
|
6
|
-
metrics?: Metrics;
|
|
7
|
-
reporter?: Reporter;
|
|
8
|
-
}, error?: unknown) => Promise<void>;
|
|
9
4
|
interface CreateRenderOptions {
|
|
10
5
|
pwd: string;
|
|
11
6
|
routes: ServerRoute[];
|
|
@@ -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';
|
|
@@ -27,6 +27,11 @@ type FallbackInput = {
|
|
|
27
27
|
metrics?: Metrics;
|
|
28
28
|
reporter?: Reporter;
|
|
29
29
|
};
|
|
30
|
+
export type OnFallback = (reason: FallbackReason, utils: {
|
|
31
|
+
logger: Logger;
|
|
32
|
+
metrics?: Metrics;
|
|
33
|
+
reporter?: Reporter;
|
|
34
|
+
}, error?: unknown) => Promise<void>;
|
|
30
35
|
export type APIServerStartInput = {
|
|
31
36
|
pwd: string;
|
|
32
37
|
prefix?: string;
|
|
@@ -100,6 +105,7 @@ export interface GetRenderHandlerOptions {
|
|
|
100
105
|
pwd: string;
|
|
101
106
|
routes: ServerRoute[];
|
|
102
107
|
config: UserConfig;
|
|
108
|
+
onFallback?: OnFallback;
|
|
103
109
|
cacheConfig?: CacheConfig;
|
|
104
110
|
staticGenerate?: boolean;
|
|
105
111
|
metaName?: string;
|
|
@@ -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.
|
|
18
|
+
"version": "2.59.0",
|
|
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.
|
|
57
|
-
"@modern-js/utils": "2.
|
|
58
|
-
"@modern-js/runtime-utils": "2.
|
|
56
|
+
"@modern-js/plugin": "2.59.0",
|
|
57
|
+
"@modern-js/utils": "2.59.0",
|
|
58
|
+
"@modern-js/runtime-utils": "2.59.0"
|
|
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.
|
|
69
|
-
"@scripts/build": "2.
|
|
70
|
-
"@scripts/jest-config": "2.
|
|
68
|
+
"@modern-js/types": "2.59.0",
|
|
69
|
+
"@scripts/build": "2.59.0",
|
|
70
|
+
"@scripts/jest-config": "2.59.0"
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"publishConfig": {
|