@modern-js/server-core 2.54.6 → 2.56.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/plugins/resource.js +1 -1
- package/dist/cjs/constants.js +12 -9
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/customServer/index.js +5 -5
- package/dist/cjs/plugins/index.js +7 -3
- package/dist/cjs/plugins/log.js +3 -3
- package/dist/cjs/plugins/monitors.js +183 -0
- package/dist/cjs/plugins/render/dataHandler.js +3 -2
- package/dist/cjs/plugins/render/index.js +6 -4
- package/dist/cjs/plugins/render/render.js +32 -15
- package/dist/cjs/plugins/render/ssrCache.js +72 -83
- package/dist/cjs/plugins/render/ssrRender.js +40 -145
- package/dist/cjs/types/requestHandler.js +16 -0
- package/dist/cjs/utils/error.js +3 -3
- package/dist/cjs/utils/transformStream.js +1 -1
- package/dist/esm/adapters/node/plugins/resource.js +1 -1
- package/dist/esm/constants.js +10 -8
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugins/customServer/index.js +8 -8
- package/dist/esm/plugins/index.js +4 -2
- package/dist/esm/plugins/log.js +4 -4
- package/dist/esm/plugins/monitors.js +261 -0
- package/dist/esm/plugins/render/dataHandler.js +4 -3
- package/dist/esm/plugins/render/index.js +6 -4
- package/dist/esm/plugins/render/render.js +51 -24
- package/dist/esm/plugins/render/ssrCache.js +101 -131
- package/dist/esm/plugins/render/ssrRender.js +55 -175
- package/dist/esm/types/requestHandler.js +0 -0
- package/dist/esm/utils/error.js +3 -3
- package/dist/esm/utils/transformStream.js +16 -2
- package/dist/esm-node/adapters/node/plugins/resource.js +1 -1
- package/dist/esm-node/constants.js +10 -8
- package/dist/esm-node/index.js +1 -0
- package/dist/esm-node/plugins/customServer/index.js +6 -6
- package/dist/esm-node/plugins/index.js +4 -2
- package/dist/esm-node/plugins/log.js +3 -3
- package/dist/esm-node/plugins/monitors.js +156 -0
- package/dist/esm-node/plugins/render/dataHandler.js +3 -2
- package/dist/esm-node/plugins/render/index.js +5 -3
- package/dist/esm-node/plugins/render/render.js +33 -16
- package/dist/esm-node/plugins/render/ssrCache.js +73 -74
- package/dist/esm-node/plugins/render/ssrRender.js +43 -137
- package/dist/esm-node/types/requestHandler.js +0 -0
- package/dist/esm-node/utils/error.js +3 -3
- package/dist/esm-node/utils/transformStream.js +1 -1
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/plugins/monitors.d.ts +6 -0
- package/dist/types/plugins/render/dataHandler.d.ts +1 -1
- package/dist/types/plugins/render/render.d.ts +3 -2
- package/dist/types/plugins/render/ssrCache.d.ts +7 -11
- package/dist/types/plugins/render/ssrRender.d.ts +10 -10
- package/dist/types/types/config/html.d.ts +11 -0
- package/dist/types/types/config/output.d.ts +8 -0
- package/dist/types/types/render.d.ts +7 -4
- package/dist/types/types/requestHandler.d.ts +41 -0
- package/dist/types/types/server.d.ts +13 -4
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/transformStream.d.ts +1 -1
- package/package.json +7 -8
- package/dist/cjs/plugins/monitor.js +0 -87
- package/dist/cjs/plugins/render/serverTiming.js +0 -40
- package/dist/esm/plugins/monitor.js +0 -120
- package/dist/esm/plugins/render/serverTiming.js +0 -21
- package/dist/esm-node/plugins/monitor.js +0 -62
- package/dist/esm-node/plugins/render/serverTiming.js +0 -16
- package/dist/types/plugins/monitor.d.ts +0 -9
- package/dist/types/plugins/render/serverTiming.d.ts +0 -7
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { X_MODERNJS_RENDER, X_RENDER_CACHE } from "../../constants";
|
|
5
|
-
import { ServerTiming } from "./serverTiming";
|
|
1
|
+
import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
|
|
2
|
+
import { parseHeaders, getPathname } from "../../utils";
|
|
3
|
+
import { X_MODERNJS_RENDER } from "../../constants";
|
|
6
4
|
import { matchCacheControl, getCacheResult } from "./ssrCache";
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
reportError() {
|
|
11
|
-
},
|
|
12
|
-
reportTiming() {
|
|
13
|
-
},
|
|
14
|
-
reportInfo() {
|
|
15
|
-
},
|
|
16
|
-
reportWarn() {
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
async function ssrRender(request, { routeInfo, html, staticGenerate, nonce, metaName, reporter, logger, nodeReq, serverManifest, locals, params, metrics, loaderContext, cacheConfig }) {
|
|
5
|
+
const SERVER_RUNTIME_ENTRY = "requestHandler";
|
|
6
|
+
async function ssrRender(request, { routeInfo, html, config: userConfig, staticGenerate, nodeReq, serverManifest, locals, params, loaderContext, reporter, cacheConfig, logger, metrics, onError, onTiming }) {
|
|
20
7
|
var _serverManifest_renderBundles;
|
|
21
8
|
const { entryName } = routeInfo;
|
|
22
9
|
const loadableStats = serverManifest.loadableStats || {};
|
|
23
10
|
const routeManifest = serverManifest.routeManifest || {};
|
|
24
|
-
const host = getHost(request);
|
|
25
|
-
const isSpider = isbot.default(request.headers.get("user-agent"));
|
|
26
|
-
const responseProxy = new ResponseProxy();
|
|
27
|
-
const query = parseQuery(request);
|
|
28
11
|
const headers = parseHeaders(request);
|
|
29
12
|
if (nodeReq) {
|
|
30
13
|
for (const key in nodeReq.headers) {
|
|
@@ -33,103 +16,46 @@ async function ssrRender(request, { routeInfo, html, staticGenerate, nonce, meta
|
|
|
33
16
|
}
|
|
34
17
|
}
|
|
35
18
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
status(code) {
|
|
51
|
-
responseProxy.status = code;
|
|
52
|
-
},
|
|
53
|
-
locals: locals || {}
|
|
19
|
+
const renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || MAIN_ENTRY_NAME];
|
|
20
|
+
if (!renderBundle) {
|
|
21
|
+
throw new Error(`Can't found renderBundle ${entryName || MAIN_ENTRY_NAME}`);
|
|
22
|
+
}
|
|
23
|
+
const requestHandler = await renderBundle[SERVER_RUNTIME_ENTRY];
|
|
24
|
+
const config = createRequestHandlerConfig(userConfig);
|
|
25
|
+
const requestHandlerOptions = {
|
|
26
|
+
resource: {
|
|
27
|
+
route: routeInfo,
|
|
28
|
+
loadableStats,
|
|
29
|
+
routeManifest,
|
|
30
|
+
htmlTemplate: html,
|
|
31
|
+
entryName: entryName || MAIN_ENTRY_NAME
|
|
54
32
|
},
|
|
55
|
-
|
|
56
|
-
template: html,
|
|
57
|
-
loadableStats,
|
|
33
|
+
params,
|
|
58
34
|
loaderContext,
|
|
59
|
-
|
|
60
|
-
|
|
35
|
+
config,
|
|
36
|
+
locals,
|
|
37
|
+
reporter,
|
|
61
38
|
staticGenerate,
|
|
62
39
|
logger,
|
|
63
40
|
metrics,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/** @deprecated node req */
|
|
67
|
-
req: nodeReq || request,
|
|
68
|
-
/** @deprecated node res */
|
|
69
|
-
res: void 0,
|
|
70
|
-
isSpider,
|
|
71
|
-
nonce
|
|
41
|
+
onError,
|
|
42
|
+
onTiming
|
|
72
43
|
};
|
|
73
|
-
const renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || MAIN_ENTRY_NAME];
|
|
74
|
-
if (!renderBundle) {
|
|
75
|
-
throw new Error(`Can't found renderBundle ${entryName || MAIN_ENTRY_NAME}`);
|
|
76
|
-
}
|
|
77
|
-
const runtimeEnv = getRuntimeEnv();
|
|
78
|
-
let ssrResult;
|
|
79
|
-
let cacheStatus;
|
|
80
|
-
const render = renderBundle[SERVER_RENDER_FUNCTION_NAME];
|
|
81
44
|
const cacheControl = await matchCacheControl(cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.strategy, nodeReq || new IncomingMessgeProxy(request));
|
|
45
|
+
let response;
|
|
82
46
|
if (cacheControl) {
|
|
83
|
-
|
|
47
|
+
response = await getCacheResult(request, {
|
|
84
48
|
cacheControl,
|
|
85
49
|
container: cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.container,
|
|
86
|
-
|
|
87
|
-
|
|
50
|
+
requestHandler,
|
|
51
|
+
requestHandlerOptions
|
|
88
52
|
});
|
|
89
|
-
ssrResult = data2;
|
|
90
|
-
cacheStatus = status;
|
|
91
53
|
} else {
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
const { redirection } = ssrContext;
|
|
95
|
-
if (cacheStatus) {
|
|
96
|
-
responseProxy.headers.set(X_RENDER_CACHE, cacheStatus);
|
|
97
|
-
}
|
|
98
|
-
responseProxy.headers.set(X_MODERNJS_RENDER, "server");
|
|
99
|
-
if (redirection.url) {
|
|
100
|
-
const { headers: headers2 } = responseProxy;
|
|
101
|
-
headers2.set("Location", redirection.url);
|
|
102
|
-
return new Response(null, {
|
|
103
|
-
status: redirection.status || 302,
|
|
104
|
-
headers: {
|
|
105
|
-
Location: redirection.url
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const { Readable } = await import("stream").catch((_) => ({
|
|
110
|
-
Readable: void 0
|
|
111
|
-
}));
|
|
112
|
-
const streamModule = "../../adapters/node/polyfills/stream";
|
|
113
|
-
const { createReadableStreamFromReadable } = runtimeEnv === "node" ? await import(streamModule).catch((_) => ({
|
|
114
|
-
createReadableStreamFromReadable: void 0
|
|
115
|
-
})) : {
|
|
116
|
-
createReadableStreamFromReadable: void 0
|
|
117
|
-
};
|
|
118
|
-
const data = Readable && ssrResult instanceof Readable ? (createReadableStreamFromReadable === null || createReadableStreamFromReadable === void 0 ? void 0 : createReadableStreamFromReadable(ssrResult)) || "" : ssrResult;
|
|
119
|
-
if (typeof data !== "string") {
|
|
120
|
-
responseProxy.headers.set("transfer-encoding", "chunked");
|
|
121
|
-
}
|
|
122
|
-
return new Response(data, {
|
|
123
|
-
status: responseProxy.status,
|
|
124
|
-
headers: responseProxy.headers
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
class ResponseProxy {
|
|
128
|
-
constructor() {
|
|
129
|
-
this.headers = new Headers();
|
|
130
|
-
this.status = 200;
|
|
131
|
-
this.headers.set("content-type", "text/html; charset=UTF-8");
|
|
54
|
+
response = await requestHandler(request, requestHandlerOptions);
|
|
132
55
|
}
|
|
56
|
+
response.headers.set(X_MODERNJS_RENDER, "server");
|
|
57
|
+
response.headers.set("content-type", "text/html; charset=UTF-8");
|
|
58
|
+
return response;
|
|
133
59
|
}
|
|
134
60
|
class IncomingMessgeProxy {
|
|
135
61
|
constructor(req) {
|
|
@@ -141,38 +67,18 @@ class IncomingMessgeProxy {
|
|
|
141
67
|
this.url = getPathname(req);
|
|
142
68
|
}
|
|
143
69
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
host = nodeReq.headers.host;
|
|
156
|
-
}
|
|
157
|
-
host = host.split(/\s*,\s*/, 1)[0] || "undefined";
|
|
158
|
-
return host;
|
|
159
|
-
}
|
|
160
|
-
const href = `${getProtocal()}://${getHost2()}${nodeReq.url || ""}`;
|
|
161
|
-
return href;
|
|
162
|
-
}
|
|
163
|
-
function getPathnameFromNodeReq(nodeReq) {
|
|
164
|
-
const { url } = nodeReq;
|
|
165
|
-
if (!url) {
|
|
166
|
-
return "/";
|
|
167
|
-
}
|
|
168
|
-
const match = url.match(/\/[^?]*/);
|
|
169
|
-
let pathname = match ? match[0] : "/";
|
|
170
|
-
if (pathname !== "/" && pathname.endsWith("/")) {
|
|
171
|
-
pathname = pathname.slice(0, -1);
|
|
172
|
-
}
|
|
173
|
-
return pathname;
|
|
70
|
+
function createRequestHandlerConfig(userConfig) {
|
|
71
|
+
const { output, server, security, html } = userConfig;
|
|
72
|
+
return {
|
|
73
|
+
ssr: server === null || server === void 0 ? void 0 : server.ssr,
|
|
74
|
+
ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
|
|
75
|
+
nonce: security === null || security === void 0 ? void 0 : security.nonce,
|
|
76
|
+
enableInlineScripts: output === null || output === void 0 ? void 0 : output.enableInlineScripts,
|
|
77
|
+
enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
|
|
78
|
+
crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
|
|
79
|
+
scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading
|
|
80
|
+
};
|
|
174
81
|
}
|
|
175
82
|
export {
|
|
176
|
-
getPathnameFromNodeReq,
|
|
177
83
|
ssrRender
|
|
178
84
|
};
|
|
File without changes
|
|
@@ -43,11 +43,11 @@ var ErrorDigest;
|
|
|
43
43
|
ErrorDigest2["EINTER"] = "Internal server error";
|
|
44
44
|
ErrorDigest2["ERENDER"] = "SSR render failed";
|
|
45
45
|
})(ErrorDigest || (ErrorDigest = {}));
|
|
46
|
-
function onError(digest, error,
|
|
46
|
+
function onError(digest, error, monitors, req) {
|
|
47
47
|
const headerData = req && parseHeaders(req);
|
|
48
48
|
headerData && delete headerData.cookie;
|
|
49
|
-
if (
|
|
50
|
-
|
|
49
|
+
if (monitors) {
|
|
50
|
+
monitors.error(req ? `Server Error - ${digest}, error = %s, req.url = %s, req.headers = %o` : `Server Error - ${digest}, error = %s`, error instanceof Error ? error.stack || error.message : error, req === null || req === void 0 ? void 0 : req.url, headerData);
|
|
51
51
|
} else if (req) {
|
|
52
52
|
console.error(`Server Error - ${digest}, error = ${error instanceof Error ? error.stack || error.message : error}, req.url = ${req.url}, req.headers = ${JSON.stringify(headerData)}`);
|
|
53
53
|
} else {
|
|
@@ -4,7 +4,7 @@ function createTransformStream(fn) {
|
|
|
4
4
|
return new TransformStream({
|
|
5
5
|
async transform(chunk, controller) {
|
|
6
6
|
const content = decoder.decode(chunk);
|
|
7
|
-
const newContent = await fn(content);
|
|
7
|
+
const newContent = fn ? await fn(content) : content;
|
|
8
8
|
controller.enqueue(encoder.encode(newContent));
|
|
9
9
|
}
|
|
10
10
|
});
|
|
@@ -15,11 +15,12 @@ export declare const REPLACE_REG: {
|
|
|
15
15
|
body: string;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export declare enum
|
|
18
|
+
export declare enum ServerTimings {
|
|
19
19
|
SERVER_HANDLE_REQUEST = "server-handle-request",
|
|
20
20
|
SERVER_MIDDLEWARE = "server-middleware",
|
|
21
21
|
SERVER_HOOK_AFTER_RENDER = "server-hook-after-render",
|
|
22
22
|
SERVER_HOOK_AFTER_MATCH = "server-hook-after-match"
|
|
23
23
|
}
|
|
24
|
+
export declare const SERVER_TIMING = "Server-Timing";
|
|
24
25
|
export declare const X_RENDER_CACHE = "x-render-cache";
|
|
25
26
|
export declare const X_MODERNJS_RENDER = "x-modernjs-render";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { faviconPlugin } from './favicon';
|
|
|
3
3
|
export { processedByPlugin } from './processedBy';
|
|
4
4
|
export { getLoaderCtx } from './customServer';
|
|
5
5
|
export { logPlugin } from './log';
|
|
6
|
-
export {
|
|
6
|
+
export { initMonitorsPlugin, injectServerTiming, injectloggerPluigin, } from './monitors';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Logger } from '@modern-js/types';
|
|
2
|
+
import type { Context, Next, ServerEnv, ServerPlugin } from '../types';
|
|
3
|
+
export declare const initMonitorsPlugin: () => ServerPlugin;
|
|
4
|
+
export declare const injectloggerPluigin: (logger: Logger) => ServerPlugin;
|
|
5
|
+
export declare const injectServerTiming: (metaName?: string) => ServerPlugin;
|
|
6
|
+
export declare function initReporter(entryName: string): (c: Context<ServerEnv>, next: Next) => Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ServerRoute } from '@modern-js/types';
|
|
2
2
|
import { SSRRenderOptions } from './ssrRender';
|
|
3
|
-
export declare const dataHandler: (request: Request, { routeInfo, serverRoutes, reporter,
|
|
3
|
+
export declare const dataHandler: (request: Request, { routeInfo, serverRoutes, reporter, onError, onTiming, serverManifest, }: SSRRenderOptions & {
|
|
4
4
|
serverRoutes: ServerRoute[];
|
|
5
5
|
}) => Promise<Response | void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
|
|
2
|
-
import type { CacheConfig, FallbackReason } from '../../types';
|
|
2
|
+
import type { CacheConfig, FallbackReason, UserConfig } from '../../types';
|
|
3
3
|
import { Render } from '../../types';
|
|
4
4
|
export type OnFallback = (reason: FallbackReason, utils: {
|
|
5
5
|
logger: Logger;
|
|
@@ -9,6 +9,7 @@ export type OnFallback = (reason: FallbackReason, utils: {
|
|
|
9
9
|
interface CreateRenderOptions {
|
|
10
10
|
pwd: string;
|
|
11
11
|
routes: ServerRoute[];
|
|
12
|
+
config: UserConfig;
|
|
12
13
|
cacheConfig?: CacheConfig;
|
|
13
14
|
staticGenerate?: boolean;
|
|
14
15
|
onFallback?: OnFallback;
|
|
@@ -16,5 +17,5 @@ interface CreateRenderOptions {
|
|
|
16
17
|
forceCSR?: boolean;
|
|
17
18
|
nonce?: string;
|
|
18
19
|
}
|
|
19
|
-
export declare function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR,
|
|
20
|
+
export declare function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, config, onFallback: onFallbackFn, }: CreateRenderOptions): Promise<Render>;
|
|
20
21
|
export {};
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import type { IncomingMessage } from 'http';
|
|
4
|
-
import type * as nodeStream from 'stream';
|
|
5
3
|
import type { CacheControl, CacheOption, Container } from '@modern-js/types';
|
|
6
|
-
import
|
|
4
|
+
import { RequestHandler, RequestHandlerOptions } from '../../types/requestHandler';
|
|
7
5
|
export type CacheStatus = 'hit' | 'stale' | 'expired' | 'miss';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
status?: CacheStatus;
|
|
11
|
-
};
|
|
12
|
-
export declare function matchCacheControl(cacheOption?: CacheOption, req?: IncomingMessage): CacheControl | Promise<CacheControl> | undefined;
|
|
6
|
+
type MaybeAsync<T> = Promise<T> | T;
|
|
7
|
+
export declare function matchCacheControl(cacheOption?: CacheOption, req?: IncomingMessage): MaybeAsync<CacheControl | undefined | false>;
|
|
13
8
|
export interface GetCacheResultOptions {
|
|
14
9
|
cacheControl: CacheControl;
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
requestHandler: RequestHandler;
|
|
11
|
+
requestHandlerOptions: RequestHandlerOptions;
|
|
17
12
|
container?: Container;
|
|
18
13
|
}
|
|
19
|
-
export declare function getCacheResult(request: Request, options: GetCacheResultOptions): Promise<
|
|
14
|
+
export declare function getCacheResult(request: Request, options: GetCacheResultOptions): Promise<Response>;
|
|
15
|
+
export {};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { IncomingMessage } from 'http';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import type { Reporter, ServerRoute, Logger, Metrics } from '@modern-js/types';
|
|
4
|
+
import { OnError, OnTiming, Params } from '../../types/requestHandler';
|
|
5
|
+
import { CacheConfig, ServerManifest, UserConfig } from '../../types';
|
|
6
6
|
export interface SSRRenderOptions {
|
|
7
7
|
pwd: string;
|
|
8
8
|
html: string;
|
|
9
9
|
routeInfo: ServerRoute;
|
|
10
10
|
staticGenerate: boolean;
|
|
11
|
-
|
|
12
|
-
logger: Logger;
|
|
11
|
+
config: UserConfig;
|
|
13
12
|
serverManifest: ServerManifest;
|
|
14
13
|
loaderContext: Map<string, unknown>;
|
|
15
14
|
params: Params;
|
|
15
|
+
logger: Logger;
|
|
16
|
+
metrics?: Metrics;
|
|
17
|
+
reporter?: Reporter;
|
|
16
18
|
/** Produce by custom server hook */
|
|
17
19
|
locals?: Record<string, any>;
|
|
18
20
|
cacheConfig?: CacheConfig;
|
|
19
|
-
reporter?: Reporter;
|
|
20
|
-
metrics?: Metrics;
|
|
21
21
|
nodeReq?: IncomingMessage;
|
|
22
|
-
|
|
22
|
+
onError?: OnError;
|
|
23
|
+
onTiming?: OnTiming;
|
|
23
24
|
}
|
|
24
|
-
export declare function ssrRender(request: Request, { routeInfo, html, staticGenerate,
|
|
25
|
-
export declare function getPathnameFromNodeReq(nodeReq: IncomingMessage): string;
|
|
25
|
+
export declare function ssrRender(request: Request, { routeInfo, html, config: userConfig, staticGenerate, nodeReq, serverManifest, locals, params, loaderContext, reporter, cacheConfig, logger, metrics, onError, onTiming, }: SSRRenderOptions): Promise<Response>;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
export type CrossOrigin = 'anonymous' | 'use-credentials';
|
|
2
|
+
export type ScriptLoading = 'defer' | 'module' | 'blocking';
|
|
1
3
|
export interface HtmlUserConfig {
|
|
2
4
|
favicon?: string;
|
|
3
5
|
faviconByEntries?: Record<string, string | undefined>;
|
|
6
|
+
/**
|
|
7
|
+
* Set the [crossorigin](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) attribute
|
|
8
|
+
* of the `<script>` tag.
|
|
9
|
+
*/
|
|
10
|
+
crossorigin?: boolean | CrossOrigin;
|
|
11
|
+
/**
|
|
12
|
+
* Set the loading mode of the `<script>` tag.
|
|
13
|
+
*/
|
|
14
|
+
scriptLoading?: ScriptLoading;
|
|
4
15
|
}
|
|
5
16
|
export type HtmlNormalizedConfig = HtmlUserConfig;
|
|
@@ -15,5 +15,13 @@ export interface OutputUserConfig {
|
|
|
15
15
|
path?: string;
|
|
16
16
|
assetPrefix?: string;
|
|
17
17
|
polyfill?: 'entry' | 'usage' | 'ua' | 'off';
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use `output.inlineScripts` instead
|
|
20
|
+
*/
|
|
21
|
+
enableInlineScripts?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use `output.inlineStyles` instead
|
|
24
|
+
*/
|
|
25
|
+
enableInlineStyles?: boolean;
|
|
18
26
|
}
|
|
19
27
|
export type OutputNormalizedConfig = OutputUserConfig;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { IncomingMessage } from 'node:http';
|
|
3
|
-
import type { Logger, Metrics, Reporter } from '@modern-js/types';
|
|
3
|
+
import type { Logger, Metrics, Monitors, Reporter } from '@modern-js/types';
|
|
4
4
|
import type { ServerManifest } from './server';
|
|
5
5
|
export interface RenderOptions {
|
|
6
|
-
logger: Logger;
|
|
7
6
|
loaderContext?: Map<string, unknown>;
|
|
8
7
|
/** ssr render html templates */
|
|
9
8
|
templates: Record<string, string>;
|
|
10
9
|
/** Communicating with custom server hook & modern ssr runtime. */
|
|
11
10
|
locals?: Record<string, any>;
|
|
12
|
-
/**
|
|
11
|
+
/** @deprecated */
|
|
12
|
+
logger: Logger;
|
|
13
|
+
/** @deprecated */
|
|
13
14
|
metrics?: Metrics;
|
|
14
|
-
|
|
15
|
+
/** @deprecated */
|
|
15
16
|
reporter?: Reporter;
|
|
17
|
+
monitors?: Monitors;
|
|
18
|
+
serverManifest: ServerManifest;
|
|
16
19
|
nodeReq?: IncomingMessage;
|
|
17
20
|
}
|
|
18
21
|
export type Render = (request: Request, options: RenderOptions) => Promise<Response>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Metrics, Reporter, ServerRoute, Logger } from '@modern-js/types';
|
|
2
|
+
import { ServerUserConfig } from './config';
|
|
3
|
+
export type Resource = {
|
|
4
|
+
loadableStats: Record<string, any>;
|
|
5
|
+
routeManifest: Record<string, any>;
|
|
6
|
+
route: ServerRoute;
|
|
7
|
+
htmlTemplate: string;
|
|
8
|
+
entryName: string;
|
|
9
|
+
};
|
|
10
|
+
export type Params = Record<string, any>;
|
|
11
|
+
export type RequestHandlerConfig = {
|
|
12
|
+
nonce?: string;
|
|
13
|
+
crossorigin?: boolean | 'anonymous' | 'use-credentials';
|
|
14
|
+
scriptLoading?: 'defer' | 'blocking' | 'module' | 'async';
|
|
15
|
+
enableInlineStyles?: boolean | RegExp;
|
|
16
|
+
enableInlineScripts?: boolean | RegExp;
|
|
17
|
+
ssr?: ServerUserConfig['ssr'];
|
|
18
|
+
ssrByEntries?: ServerUserConfig['ssrByEntries'];
|
|
19
|
+
};
|
|
20
|
+
export type LoaderContext = Map<string, any>;
|
|
21
|
+
export type OnError = (err: unknown) => void;
|
|
22
|
+
export type OnTiming = (name: string, dur: number) => void;
|
|
23
|
+
export type RequestHandlerOptions = {
|
|
24
|
+
resource: Resource;
|
|
25
|
+
config: RequestHandlerConfig;
|
|
26
|
+
params: Params;
|
|
27
|
+
loaderContext: LoaderContext;
|
|
28
|
+
/** @deprecated */
|
|
29
|
+
locals?: Record<string, any>;
|
|
30
|
+
/** @deprecated */
|
|
31
|
+
staticGenerate?: boolean;
|
|
32
|
+
/** @deprecated ssr runtime code need reporter instance */
|
|
33
|
+
reporter?: Reporter;
|
|
34
|
+
/** @deprecated */
|
|
35
|
+
logger: Logger;
|
|
36
|
+
/** @deprecated */
|
|
37
|
+
metrics?: Metrics;
|
|
38
|
+
onError?: OnError;
|
|
39
|
+
onTiming?: OnTiming;
|
|
40
|
+
};
|
|
41
|
+
export type RequestHandler = (request: Request, options: RequestHandlerOptions) => Promise<Response>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Readable } from 'node:stream';
|
|
3
|
-
import type { Metrics, Logger, Reporter, BaseSSRServerContext, ServerRoute, NestedRoute } from '@modern-js/types';
|
|
3
|
+
import type { Metrics, Logger, Reporter, BaseSSRServerContext, ServerRoute, NestedRoute, Monitors } from '@modern-js/types';
|
|
4
|
+
import { RequestHandler as BundleRequestHandler, OnError, OnTiming } from './requestHandler';
|
|
4
5
|
export type SSRServerContext = BaseSSRServerContext & {
|
|
5
6
|
staticGenerate?: boolean;
|
|
6
7
|
};
|
|
@@ -11,12 +12,16 @@ type ServerLoaderBundle = {
|
|
|
11
12
|
handleRequest: (options: {
|
|
12
13
|
request: Request;
|
|
13
14
|
serverRoutes: ServerRoute[];
|
|
14
|
-
context: any;
|
|
15
15
|
routes: NestedRoute[];
|
|
16
|
+
context: {
|
|
17
|
+
reporter?: Reporter;
|
|
18
|
+
};
|
|
19
|
+
onError?: OnError;
|
|
20
|
+
onTiming?: OnTiming;
|
|
16
21
|
}) => Promise<any>;
|
|
17
22
|
};
|
|
18
23
|
type ServerRenderBundle = {
|
|
19
|
-
|
|
24
|
+
requestHandler: Promise<BundleRequestHandler>;
|
|
20
25
|
};
|
|
21
26
|
export type ServerManifest = {
|
|
22
27
|
loaderBundles?: Record<string, ServerLoaderBundle>;
|
|
@@ -25,8 +30,13 @@ export type ServerManifest = {
|
|
|
25
30
|
routeManifest?: Record<string, any>;
|
|
26
31
|
};
|
|
27
32
|
type ServerVariables = {
|
|
33
|
+
/** @deprecated */
|
|
28
34
|
logger: Logger;
|
|
35
|
+
/** @deprecated */
|
|
29
36
|
reporter?: Reporter;
|
|
37
|
+
/** @deprecated */
|
|
38
|
+
metrics?: Metrics;
|
|
39
|
+
monitors: Monitors;
|
|
30
40
|
serverManifest?: ServerManifest;
|
|
31
41
|
templates?: Record<string, string>;
|
|
32
42
|
/**
|
|
@@ -36,7 +46,6 @@ type ServerVariables = {
|
|
|
36
46
|
* Custom by ssrRuntime.
|
|
37
47
|
*/
|
|
38
48
|
locals?: Record<string, any>;
|
|
39
|
-
metrics?: Metrics;
|
|
40
49
|
};
|
|
41
50
|
export type ServerEnv = {
|
|
42
51
|
Variables: ServerVariables;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Monitors } from '@modern-js/types';
|
|
2
2
|
export declare const createErrorHtml: (status: number) => string;
|
|
3
3
|
export declare enum ErrorDigest {
|
|
4
4
|
ENOTF = "Page could not be found",
|
|
5
5
|
EINTER = "Internal server error",
|
|
6
6
|
ERENDER = "SSR render failed"
|
|
7
7
|
}
|
|
8
|
-
export declare function onError(digest: ErrorDigest, error: Error | string,
|
|
8
|
+
export declare function onError(digest: ErrorDigest, error: Error | string, monitors?: Monitors, req?: Request): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MaybeAsync } from '@modern-js/plugin';
|
|
2
2
|
type TransformCb = (tempalte: string) => MaybeAsync<string>;
|
|
3
|
-
export declare function createTransformStream(fn
|
|
3
|
+
export declare function createTransformStream(fn?: TransformCb): TransformStream<any, any>;
|
|
4
4
|
export declare function transformResponse(response: Response, transformCb: Array<TransformCb> | TransformCb): Response;
|
|
5
5
|
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.56.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -52,10 +52,9 @@
|
|
|
52
52
|
"@web-std/file": "^3.0.3",
|
|
53
53
|
"hono": "^3.12.2",
|
|
54
54
|
"ts-deepmerge": "7.0.0",
|
|
55
|
-
"
|
|
56
|
-
"@modern-js/
|
|
57
|
-
"@modern-js/
|
|
58
|
-
"@modern-js/utils": "2.54.6"
|
|
55
|
+
"@modern-js/plugin": "2.56.0",
|
|
56
|
+
"@modern-js/runtime-utils": "2.56.0",
|
|
57
|
+
"@modern-js/utils": "2.56.0"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
60
|
"@types/jest": "^29",
|
|
@@ -65,9 +64,9 @@
|
|
|
65
64
|
"jest": "^29",
|
|
66
65
|
"ts-jest": "^29.1.0",
|
|
67
66
|
"typescript": "^5",
|
|
68
|
-
"@
|
|
69
|
-
"@scripts/
|
|
70
|
-
"@
|
|
67
|
+
"@modern-js/types": "2.56.0",
|
|
68
|
+
"@scripts/build": "2.56.0",
|
|
69
|
+
"@scripts/jest-config": "2.56.0"
|
|
71
70
|
},
|
|
72
71
|
"sideEffects": false,
|
|
73
72
|
"publishConfig": {
|