@modern-js/server-core 2.54.5 → 2.55.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/index.js +3 -1
- package/dist/cjs/plugins/render/dataHandler.js +3 -2
- package/dist/cjs/plugins/render/index.js +1 -1
- package/dist/cjs/plugins/render/render.js +37 -13
- package/dist/cjs/plugins/render/serverTiming.js +6 -4
- 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/transformStream.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugins/render/dataHandler.js +4 -3
- package/dist/esm/plugins/render/index.js +1 -1
- package/dist/esm/plugins/render/render.js +56 -22
- package/dist/esm/plugins/render/serverTiming.js +12 -4
- 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/transformStream.js +16 -2
- package/dist/esm-node/index.js +1 -0
- package/dist/esm-node/plugins/render/dataHandler.js +3 -2
- package/dist/esm-node/plugins/render/index.js +1 -1
- package/dist/esm-node/plugins/render/render.js +38 -14
- package/dist/esm-node/plugins/render/serverTiming.js +6 -4
- 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/transformStream.js +1 -1
- package/dist/types/index.d.ts +1 -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/serverTiming.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/requestHandler.d.ts +43 -0
- package/dist/types/types/server.d.ts +7 -2
- package/dist/types/utils/transformStream.d.ts +1 -1
- package/package.json +7 -8
|
@@ -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
|
|
@@ -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
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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,7 +1,8 @@
|
|
|
1
1
|
import { ServerTiming as ServerTimingInterafce } from '@modern-js/types';
|
|
2
2
|
export declare class ServerTiming implements ServerTimingInterafce {
|
|
3
|
-
private
|
|
3
|
+
private headerList;
|
|
4
4
|
private meta;
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(meta: string);
|
|
6
|
+
get headers(): string[];
|
|
6
7
|
addServeTiming(name: string, dur: number, desc?: string): this;
|
|
7
8
|
}
|
|
@@ -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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
disablePrerender?: boolean;
|
|
18
|
+
chunkLoadingGlobal?: string;
|
|
19
|
+
ssr?: ServerUserConfig['ssr'];
|
|
20
|
+
ssrByEntries?: ServerUserConfig['ssrByEntries'];
|
|
21
|
+
};
|
|
22
|
+
export type LoaderContext = Map<string, any>;
|
|
23
|
+
export type OnError = (err: unknown) => void;
|
|
24
|
+
export type OnTiming = (name: string, dur: number) => void;
|
|
25
|
+
export type RequestHandlerOptions = {
|
|
26
|
+
resource: Resource;
|
|
27
|
+
config: RequestHandlerConfig;
|
|
28
|
+
params: Params;
|
|
29
|
+
loaderContext: LoaderContext;
|
|
30
|
+
/** @deprecated */
|
|
31
|
+
locals?: Record<string, any>;
|
|
32
|
+
/** @deprecated */
|
|
33
|
+
staticGenerate?: boolean;
|
|
34
|
+
/** @deprecated ssr runtime code need reporter instance */
|
|
35
|
+
reporter?: Reporter;
|
|
36
|
+
/** @deprecated */
|
|
37
|
+
logger: Logger;
|
|
38
|
+
/** @deprecated */
|
|
39
|
+
metrics?: Metrics;
|
|
40
|
+
onError?: OnError;
|
|
41
|
+
onTiming?: OnTiming;
|
|
42
|
+
};
|
|
43
|
+
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
3
|
import type { Metrics, Logger, Reporter, BaseSSRServerContext, ServerRoute, NestedRoute } 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>;
|
|
@@ -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.55.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/utils": "2.
|
|
58
|
-
"@modern-js/runtime-utils": "2.54.5"
|
|
55
|
+
"@modern-js/plugin": "2.55.0",
|
|
56
|
+
"@modern-js/runtime-utils": "2.55.0",
|
|
57
|
+
"@modern-js/utils": "2.55.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
|
-
"@modern-js/types": "2.
|
|
69
|
-
"@scripts/
|
|
70
|
-
"@scripts/
|
|
67
|
+
"@modern-js/types": "2.55.0",
|
|
68
|
+
"@scripts/jest-config": "2.55.0",
|
|
69
|
+
"@scripts/build": "2.55.0"
|
|
71
70
|
},
|
|
72
71
|
"sideEffects": false,
|
|
73
72
|
"publishConfig": {
|