@modern-js/prod-server 2.35.1 → 2.36.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/constants.js +33 -27
- package/dist/cjs/index.js +41 -33
- package/dist/cjs/libs/context/context.js +71 -45
- package/dist/cjs/libs/context/index.js +27 -17
- package/dist/cjs/libs/hook-api/base.js +49 -30
- package/dist/cjs/libs/hook-api/index.js +36 -28
- package/dist/cjs/libs/hook-api/index.worker.js +39 -31
- package/dist/cjs/libs/hook-api/route.js +28 -11
- package/dist/cjs/libs/hook-api/template.js +27 -17
- package/dist/cjs/libs/hook-api/templateForStream.js +31 -14
- package/dist/cjs/libs/loadConfig.js +46 -29
- package/dist/cjs/libs/metrics.js +24 -7
- package/dist/cjs/libs/preload/flushServerHeader.js +28 -11
- package/dist/cjs/libs/preload/index.js +22 -5
- package/dist/cjs/libs/preload/parseLinks.js +49 -24
- package/dist/cjs/libs/preload/shouldFlushServerHeader.js +25 -15
- package/dist/cjs/libs/preload/transformLinks2String.js +26 -9
- package/dist/cjs/libs/proxy.js +29 -19
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +40 -22
- package/dist/cjs/libs/render/cache/__tests__/cache.test.js +26 -29
- package/dist/cjs/libs/render/cache/__tests__/cacheable.js +24 -7
- package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +24 -7
- package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +24 -7
- package/dist/cjs/libs/render/cache/index.js +29 -16
- package/dist/cjs/libs/render/cache/page-caches/index.js +26 -9
- package/dist/cjs/libs/render/cache/page-caches/lru.js +39 -13
- package/dist/cjs/libs/render/cache/spr.js +61 -42
- package/dist/cjs/libs/render/cache/type.js +15 -3
- package/dist/cjs/libs/render/cache/util.js +49 -36
- package/dist/cjs/libs/render/index.js +54 -29
- package/dist/cjs/libs/render/measure.js +27 -17
- package/dist/cjs/libs/render/reader.js +49 -33
- package/dist/cjs/libs/render/ssr.js +52 -26
- package/dist/cjs/libs/render/static.js +44 -18
- package/dist/cjs/libs/render/type.js +24 -7
- package/dist/cjs/libs/render/utils.js +29 -19
- package/dist/cjs/libs/reporter.js +24 -7
- package/dist/cjs/libs/route/index.js +30 -20
- package/dist/cjs/libs/route/matcher.js +35 -18
- package/dist/cjs/libs/route/route.js +34 -17
- package/dist/cjs/libs/serveFile.js +40 -21
- package/dist/cjs/libs/serverTiming.js +27 -10
- package/dist/cjs/renderHtml.js +17 -20
- package/dist/cjs/server/index.js +71 -45
- package/dist/cjs/server/modernServer.js +120 -95
- package/dist/cjs/server/modernServerSplit.js +29 -12
- package/dist/cjs/type.js +15 -3
- package/dist/cjs/utils.js +41 -38
- package/dist/cjs/workerServer.js +44 -34
- package/dist/esm/constants.js +14 -6
- package/dist/esm/index.js +11 -5
- package/dist/esm/libs/context/context.js +4 -1
- package/dist/esm/libs/context/index.js +5 -2
- package/dist/esm/libs/hook-api/base.js +6 -2
- package/dist/esm/libs/hook-api/index.js +11 -5
- package/dist/esm/libs/hook-api/index.worker.js +16 -10
- package/dist/esm/libs/hook-api/route.js +4 -1
- package/dist/esm/libs/hook-api/template.js +6 -2
- package/dist/esm/libs/hook-api/templateForStream.js +4 -1
- package/dist/esm/libs/loadConfig.js +8 -3
- package/dist/esm/libs/metrics.js +3 -1
- package/dist/esm/libs/preload/flushServerHeader.js +6 -3
- package/dist/esm/libs/preload/parseLinks.js +6 -3
- package/dist/esm/libs/preload/shouldFlushServerHeader.js +6 -2
- package/dist/esm/libs/preload/transformLinks2String.js +4 -1
- package/dist/esm/libs/proxy.js +9 -5
- package/dist/esm/libs/render/cache/__tests__/cacheable.js +4 -1
- package/dist/esm/libs/render/cache/__tests__/error-configuration.js +4 -1
- package/dist/esm/libs/render/cache/__tests__/matched-cache.js +4 -1
- package/dist/esm/libs/render/cache/index.js +4 -1
- package/dist/esm/libs/render/cache/page-caches/index.js +5 -2
- package/dist/esm/libs/render/cache/page-caches/lru.js +4 -1
- package/dist/esm/libs/render/cache/spr.js +11 -7
- package/dist/esm/libs/render/cache/type.js +0 -1
- package/dist/esm/libs/render/cache/util.js +18 -8
- package/dist/esm/libs/render/index.js +12 -9
- package/dist/esm/libs/render/measure.js +15 -11
- package/dist/esm/libs/render/reader.js +15 -8
- package/dist/esm/libs/render/ssr.js +11 -8
- package/dist/esm/libs/render/static.js +5 -2
- package/dist/esm/libs/render/type.js +4 -1
- package/dist/esm/libs/render/utils.js +6 -2
- package/dist/esm/libs/reporter.js +4 -1
- package/dist/esm/libs/route/index.js +5 -2
- package/dist/esm/libs/route/matcher.js +4 -1
- package/dist/esm/libs/route/route.js +4 -1
- package/dist/esm/libs/serveFile.js +6 -2
- package/dist/esm/libs/serverTiming.js +4 -1
- package/dist/esm/renderHtml.js +133 -124
- package/dist/esm/server/index.js +9 -6
- package/dist/esm/server/modernServer.js +13 -10
- package/dist/esm/server/modernServerSplit.js +4 -1
- package/dist/esm/type.js +0 -1
- package/dist/esm/utils.js +23 -12
- package/dist/esm/workerServer.js +21 -17
- package/dist/esm-node/constants.js +14 -6
- package/dist/esm-node/index.js +11 -5
- package/dist/esm-node/libs/context/context.js +4 -1
- package/dist/esm-node/libs/context/index.js +5 -2
- package/dist/esm-node/libs/hook-api/base.js +6 -2
- package/dist/esm-node/libs/hook-api/index.js +10 -4
- package/dist/esm-node/libs/hook-api/index.worker.js +10 -4
- package/dist/esm-node/libs/hook-api/route.js +4 -1
- package/dist/esm-node/libs/hook-api/template.js +6 -2
- package/dist/esm-node/libs/hook-api/templateForStream.js +4 -1
- package/dist/esm-node/libs/loadConfig.js +8 -3
- package/dist/esm-node/libs/metrics.js +3 -1
- package/dist/esm-node/libs/preload/flushServerHeader.js +4 -1
- package/dist/esm-node/libs/preload/parseLinks.js +4 -1
- package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +6 -2
- package/dist/esm-node/libs/preload/transformLinks2String.js +4 -1
- package/dist/esm-node/libs/proxy.js +6 -2
- package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +4 -1
- package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +4 -1
- package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +4 -1
- package/dist/esm-node/libs/render/cache/index.js +4 -1
- package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -1
- package/dist/esm-node/libs/render/cache/page-caches/lru.js +4 -1
- package/dist/esm-node/libs/render/cache/spr.js +6 -2
- package/dist/esm-node/libs/render/cache/type.js +0 -1
- package/dist/esm-node/libs/render/cache/util.js +18 -8
- package/dist/esm-node/libs/render/index.js +4 -1
- package/dist/esm-node/libs/render/measure.js +6 -2
- package/dist/esm-node/libs/render/reader.js +12 -5
- package/dist/esm-node/libs/render/ssr.js +4 -1
- package/dist/esm-node/libs/render/static.js +4 -1
- package/dist/esm-node/libs/render/type.js +4 -1
- package/dist/esm-node/libs/render/utils.js +6 -2
- package/dist/esm-node/libs/reporter.js +4 -1
- package/dist/esm-node/libs/route/index.js +5 -2
- package/dist/esm-node/libs/route/matcher.js +4 -1
- package/dist/esm-node/libs/route/route.js +4 -1
- package/dist/esm-node/libs/serveFile.js +6 -2
- package/dist/esm-node/libs/serverTiming.js +4 -1
- package/dist/esm-node/renderHtml.js +72 -63
- package/dist/esm-node/server/index.js +6 -3
- package/dist/esm-node/server/modernServer.js +4 -1
- package/dist/esm-node/server/modernServerSplit.js +4 -1
- package/dist/esm-node/type.js +0 -1
- package/dist/esm-node/utils.js +20 -9
- package/dist/esm-node/workerServer.js +8 -4
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -9
|
@@ -13,7 +13,7 @@ import { defaultReporter } from "../reporter";
|
|
|
13
13
|
import { headersWithoutCookie } from "../../utils";
|
|
14
14
|
const MOCK_URL_BASE = "https://modernjs.dev/";
|
|
15
15
|
var _urls = /* @__PURE__ */ new WeakMap(), _queries = /* @__PURE__ */ new WeakMap();
|
|
16
|
-
|
|
16
|
+
class ModernServerContext {
|
|
17
17
|
get logger() {
|
|
18
18
|
return this.req.logger;
|
|
19
19
|
}
|
|
@@ -200,3 +200,6 @@ export class ModernServerContext {
|
|
|
200
200
|
this.serverTiming = new ServerTiming(this.res, cutNameByHyphen((options === null || options === void 0 ? void 0 : options.metaName) || "modern-js"));
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
+
export {
|
|
204
|
+
ModernServerContext
|
|
205
|
+
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ModernServerContext } from "./context";
|
|
2
|
-
|
|
3
|
-
export {
|
|
2
|
+
const createContext = (req, res, options) => new ModernServerContext(req, res, options);
|
|
3
|
+
export {
|
|
4
|
+
ModernServerContext,
|
|
5
|
+
createContext
|
|
6
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import cookie from "cookie";
|
|
3
|
-
|
|
3
|
+
class BaseResponse {
|
|
4
4
|
get(key) {
|
|
5
5
|
return this.res.getHeader(key);
|
|
6
6
|
}
|
|
@@ -41,7 +41,7 @@ export class BaseResponse {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
class BaseRequest {
|
|
45
45
|
getCookie(key) {
|
|
46
46
|
return this._cookie[key];
|
|
47
47
|
}
|
|
@@ -66,3 +66,7 @@ export class BaseRequest {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
export {
|
|
70
|
+
BaseRequest,
|
|
71
|
+
BaseResponse
|
|
72
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RouteAPI } from "./route";
|
|
2
2
|
import { TemplateAPI } from "./template";
|
|
3
3
|
import { BaseRequest, BaseResponse } from "./base";
|
|
4
|
-
|
|
4
|
+
const base = (context) => {
|
|
5
5
|
const { res, reporter } = context;
|
|
6
6
|
return {
|
|
7
7
|
response: new BaseResponse(res),
|
|
@@ -11,21 +11,21 @@ export const base = (context) => {
|
|
|
11
11
|
metrics: context.metrics
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
const createAfterMatchContext = (context, entryName) => {
|
|
15
15
|
const baseContext = base(context);
|
|
16
16
|
return {
|
|
17
17
|
...baseContext,
|
|
18
18
|
router: new RouteAPI(entryName)
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const createAfterRenderContext = (context, content) => {
|
|
22
22
|
const baseContext = base(context);
|
|
23
23
|
return {
|
|
24
24
|
...baseContext,
|
|
25
25
|
template: new TemplateAPI(content)
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
const createMiddlewareContext = (context) => {
|
|
29
29
|
const baseContext = base(context);
|
|
30
30
|
baseContext.response.locals = context.res.locals || {};
|
|
31
31
|
return {
|
|
@@ -37,3 +37,9 @@ export const createMiddlewareContext = (context) => {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
+
export {
|
|
41
|
+
base,
|
|
42
|
+
createAfterMatchContext,
|
|
43
|
+
createAfterRenderContext,
|
|
44
|
+
createMiddlewareContext
|
|
45
|
+
};
|
|
@@ -30,7 +30,7 @@ class ServerResponse {
|
|
|
30
30
|
this.locals = res.locals;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
const base = (context) => {
|
|
34
34
|
const { req, res, logger, metrics, reporter } = context;
|
|
35
35
|
const serverResponse = new ServerResponse(res);
|
|
36
36
|
const { host, pathname, searchParams } = new URL(req.url);
|
|
@@ -53,21 +53,21 @@ export const base = (context) => {
|
|
|
53
53
|
metrics
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
-
|
|
56
|
+
const createAfterMatchContext = (context, entryName) => {
|
|
57
57
|
const baseContext = base(context);
|
|
58
58
|
return {
|
|
59
59
|
...baseContext,
|
|
60
60
|
router: new RouteAPI(entryName)
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
const createAfterRenderContext = (context, content) => {
|
|
64
64
|
const baseContext = base(context);
|
|
65
65
|
return {
|
|
66
66
|
...baseContext,
|
|
67
67
|
template: new TemplateAPI(content)
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
const createMiddlewareContext = (context) => {
|
|
71
71
|
const baseContext = base(context);
|
|
72
72
|
baseContext.response.locals = context.res.locals;
|
|
73
73
|
const { url, headers } = context.req;
|
|
@@ -83,3 +83,9 @@ export const createMiddlewareContext = (context) => {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
+
export {
|
|
87
|
+
base,
|
|
88
|
+
createAfterMatchContext,
|
|
89
|
+
createAfterRenderContext,
|
|
90
|
+
createMiddlewareContext
|
|
91
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
|
|
2
|
+
class RouteAPI {
|
|
3
3
|
redirect(url, status = 302) {
|
|
4
4
|
this.url = url;
|
|
5
5
|
this.status = status;
|
|
@@ -19,3 +19,6 @@ export class RouteAPI {
|
|
|
19
19
|
this.url = "";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
export {
|
|
23
|
+
RouteAPI
|
|
24
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
|
|
2
|
+
const RegList = {
|
|
3
3
|
before: {
|
|
4
4
|
head: "<head>",
|
|
5
5
|
body: "<body>"
|
|
@@ -9,7 +9,7 @@ export const RegList = {
|
|
|
9
9
|
body: "</body>"
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
class TemplateAPI {
|
|
13
13
|
get() {
|
|
14
14
|
return this.content;
|
|
15
15
|
}
|
|
@@ -40,3 +40,7 @@ export class TemplateAPI {
|
|
|
40
40
|
this.content = content;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
export {
|
|
44
|
+
RegList,
|
|
45
|
+
TemplateAPI
|
|
46
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transform } from "stream";
|
|
2
2
|
import { RegList } from "./template";
|
|
3
|
-
|
|
3
|
+
const templateInjectableStream = ({ prependHead, appendHead, prependBody, appendBody }) => new Transform({
|
|
4
4
|
write(chunk, _, callback) {
|
|
5
5
|
let chunk_str = chunk.toString();
|
|
6
6
|
if (prependHead) {
|
|
@@ -23,3 +23,6 @@ export const templateInjectableStream = ({ prependHead, appendHead, prependBody,
|
|
|
23
23
|
callback();
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
+
export {
|
|
27
|
+
templateInjectableStream
|
|
28
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { compatRequire, fs, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
|
3
3
|
import mergeDeep from "merge-deep";
|
|
4
|
-
|
|
4
|
+
const getServerConfigPath = (distDirectory, serverConfigFile = DEFAULT_SERVER_CONFIG) => {
|
|
5
5
|
const serverConfigPath = path.join(distDirectory, serverConfigFile);
|
|
6
6
|
return `${serverConfigPath}.js`;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const requireConfig = (serverConfigPath) => {
|
|
9
9
|
if (fs.pathExistsSync(serverConfigPath)) {
|
|
10
10
|
return compatRequire(serverConfigPath);
|
|
11
11
|
}
|
|
12
12
|
return {};
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
const loadConfig = ({ cliConfig, serverConfig, resolvedConfigPath }) => {
|
|
15
15
|
let config = null;
|
|
16
16
|
if (process.env.NODE_ENV === "production") {
|
|
17
17
|
const resolvedConfig = requireConfig(resolvedConfigPath);
|
|
@@ -27,3 +27,8 @@ export const loadConfig = ({ cliConfig, serverConfig, resolvedConfigPath }) => {
|
|
|
27
27
|
}
|
|
28
28
|
return config;
|
|
29
29
|
};
|
|
30
|
+
export {
|
|
31
|
+
getServerConfigPath,
|
|
32
|
+
loadConfig,
|
|
33
|
+
requireConfig
|
|
34
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseLinks } from "./parseLinks";
|
|
2
2
|
import { transformLinks2String } from "./transformLinks2String";
|
|
3
|
-
|
|
3
|
+
async function flushServerHeader({ serverConf, ctx, distDir, template, headers }) {
|
|
4
4
|
const { ssr: ssrConf } = serverConf || {};
|
|
5
5
|
if (typeof ssrConf !== "object") {
|
|
6
6
|
return;
|
|
@@ -20,3 +20,6 @@ export async function flushServerHeader({ serverConf, ctx, distDir, template, he
|
|
|
20
20
|
res.flushHeaders();
|
|
21
21
|
res.modernFlushedHeaders = true;
|
|
22
22
|
}
|
|
23
|
+
export {
|
|
24
|
+
flushServerHeader
|
|
25
|
+
};
|
|
@@ -3,7 +3,7 @@ import { NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, ROUTE_SPEC_FILE, fs } from
|
|
|
3
3
|
import { parse as htmlParse } from "node-html-parser";
|
|
4
4
|
import { matchRoutes } from "@modern-js/runtime-utils/remix-router";
|
|
5
5
|
import { matchEntry } from "@modern-js/runtime-utils/node";
|
|
6
|
-
|
|
6
|
+
async function parseLinks({ pathname, distDir, template }) {
|
|
7
7
|
const links = await parseLinksFromRoutes(pathname, distDir);
|
|
8
8
|
return links.concat(parseLinksFromHtml(template));
|
|
9
9
|
}
|
|
@@ -85,3 +85,6 @@ async function parseLinksFromRoutes(pathname, distDir) {
|
|
|
85
85
|
}
|
|
86
86
|
return noopLinks;
|
|
87
87
|
}
|
|
88
|
+
export {
|
|
89
|
+
parseLinks
|
|
90
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
function transformToRegExp(input) {
|
|
2
2
|
if (typeof input === "string") {
|
|
3
3
|
return new RegExp(input);
|
|
4
4
|
}
|
|
5
5
|
return input;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
8
8
|
const { ssr: ssrConf } = serverConf || {};
|
|
9
9
|
if (disablePreload) {
|
|
10
10
|
return false;
|
|
@@ -21,3 +21,7 @@ export function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
|
21
21
|
}
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
+
export {
|
|
25
|
+
shouldFlushServerHeader,
|
|
26
|
+
transformToRegExp
|
|
27
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { transformToRegExp } from "./shouldFlushServerHeader";
|
|
2
|
-
|
|
2
|
+
function transformLinks2String(links, preload) {
|
|
3
3
|
if (typeof preload === "boolean") {
|
|
4
4
|
return transformLinkToString(dedup(links));
|
|
5
5
|
}
|
|
@@ -121,3 +121,6 @@ function transformLinkToString(links) {
|
|
|
121
121
|
return as ? `<${uri}>; rel=${rel}; as=${as}${rest || ""}` : `<${uri}>; rel=${rel}${rest || ""}`;
|
|
122
122
|
}).join(", ");
|
|
123
123
|
}
|
|
124
|
+
export {
|
|
125
|
+
transformLinks2String
|
|
126
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpProxyMiddleware } from "http-proxy-middleware/dist/http-proxy-middleware";
|
|
2
2
|
import { debug } from "../utils";
|
|
3
|
-
|
|
3
|
+
function formatProxyOptions(proxyOptions) {
|
|
4
4
|
const ret = [];
|
|
5
5
|
if (Array.isArray(proxyOptions)) {
|
|
6
6
|
ret.push(...proxyOptions);
|
|
@@ -31,7 +31,7 @@ export function formatProxyOptions(proxyOptions) {
|
|
|
31
31
|
}
|
|
32
32
|
return ret;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
const createProxyHandler = (proxyOptions) => {
|
|
35
35
|
debug("createProxyHandler", proxyOptions);
|
|
36
36
|
const formattedOptionsList = formatProxyOptions(proxyOptions);
|
|
37
37
|
const proxies = [];
|
|
@@ -68,3 +68,7 @@ export const createProxyHandler = (proxyOptions) => {
|
|
|
68
68
|
handleUpgrade
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
export {
|
|
72
|
+
createProxyHandler,
|
|
73
|
+
formatProxyOptions
|
|
74
|
+
};
|
|
@@ -2,7 +2,7 @@ import { Transform } from "stream";
|
|
|
2
2
|
import { ERROR_DIGEST } from "../../../constants";
|
|
3
3
|
import { createCache } from "./spr";
|
|
4
4
|
import { namespaceHash, withCoalescedInvoke } from "./util";
|
|
5
|
-
|
|
5
|
+
var cache_default = (renderFn, ctx) => {
|
|
6
6
|
const sprCache = createCache();
|
|
7
7
|
const doRender = async (context) => {
|
|
8
8
|
const cacheContext = {
|
|
@@ -67,3 +67,6 @@ export default (renderFn, ctx) => {
|
|
|
67
67
|
};
|
|
68
68
|
return doRender;
|
|
69
69
|
};
|
|
70
|
+
export {
|
|
71
|
+
cache_default as default
|
|
72
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LRUCaches } from "./lru";
|
|
2
|
-
|
|
2
|
+
async function createPageCaches(max) {
|
|
3
3
|
const constructorOptions = {
|
|
4
4
|
max
|
|
5
5
|
};
|
|
@@ -7,3 +7,6 @@ export async function createPageCaches(max) {
|
|
|
7
7
|
await cacheInstance.init();
|
|
8
8
|
return cacheInstance;
|
|
9
9
|
}
|
|
10
|
+
export {
|
|
11
|
+
createPageCaches
|
|
12
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import LRU from "lru-cache";
|
|
3
|
-
|
|
3
|
+
class LRUCaches {
|
|
4
4
|
init() {
|
|
5
5
|
return Promise.resolve();
|
|
6
6
|
}
|
|
@@ -27,3 +27,6 @@ export class LRUCaches {
|
|
|
27
27
|
this.caches = new LRU(this.max);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
export {
|
|
31
|
+
LRUCaches
|
|
32
|
+
};
|
|
@@ -194,7 +194,7 @@ class CacheManager {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
let manager;
|
|
197
|
-
|
|
197
|
+
function createCache() {
|
|
198
198
|
if (manager) {
|
|
199
199
|
return manager;
|
|
200
200
|
}
|
|
@@ -203,6 +203,10 @@ export function createCache() {
|
|
|
203
203
|
});
|
|
204
204
|
return manager;
|
|
205
205
|
}
|
|
206
|
-
|
|
206
|
+
function destroyCache() {
|
|
207
207
|
manager = null;
|
|
208
208
|
}
|
|
209
|
+
export {
|
|
210
|
+
createCache,
|
|
211
|
+
destroyCache
|
|
212
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import url from "url";
|
|
2
|
-
|
|
2
|
+
function namespaceHash(namespace, hash) {
|
|
3
3
|
return `${namespace}/${hash}`;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function fname(lv) {
|
|
6
6
|
return `f${lv}`;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
function connectFactor(...args) {
|
|
9
9
|
return args.join("-");
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
function valueFactory(obj) {
|
|
12
12
|
if (obj instanceof url.URLSearchParams) {
|
|
13
13
|
return function(key) {
|
|
14
14
|
return obj.get(key);
|
|
@@ -23,16 +23,16 @@ export function valueFactory(obj) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
function getTime([s, ns]) {
|
|
27
27
|
return Math.floor(s * 1e3 + ns / 1e6);
|
|
28
28
|
}
|
|
29
29
|
const RE_START_IN_HEAD = /<head>/;
|
|
30
|
-
|
|
30
|
+
function cacheAddition(html, hash) {
|
|
31
31
|
const additionHtml = html.replace(RE_START_IN_HEAD, `<head><meta name="x-moden-spr" content="${hash}">`);
|
|
32
32
|
return additionHtml;
|
|
33
33
|
}
|
|
34
34
|
const globalInvokeCache = /* @__PURE__ */ new Map();
|
|
35
|
-
|
|
35
|
+
function withCoalescedInvoke(func) {
|
|
36
36
|
return async function(key, args) {
|
|
37
37
|
const entry = globalInvokeCache.get(key);
|
|
38
38
|
if (entry) {
|
|
@@ -58,7 +58,7 @@ export function withCoalescedInvoke(func) {
|
|
|
58
58
|
return future;
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
function maybeSync(fn) {
|
|
62
62
|
return (sync) => {
|
|
63
63
|
if (sync) {
|
|
64
64
|
return fn();
|
|
@@ -68,3 +68,13 @@ export function maybeSync(fn) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
export {
|
|
72
|
+
cacheAddition,
|
|
73
|
+
connectFactor,
|
|
74
|
+
fname,
|
|
75
|
+
getTime,
|
|
76
|
+
maybeSync,
|
|
77
|
+
namespaceHash,
|
|
78
|
+
valueFactory,
|
|
79
|
+
withCoalescedInvoke
|
|
80
|
+
};
|
|
@@ -7,7 +7,7 @@ import { readFile } from "./reader";
|
|
|
7
7
|
import * as ssr from "./ssr";
|
|
8
8
|
import { injectServerData } from "./utils";
|
|
9
9
|
const calcFallback = (metaName) => `x-${cutNameByHyphen(metaName)}-ssr-fallback`;
|
|
10
|
-
|
|
10
|
+
const createRenderHandler = ({ distDir, staticGenerate, conf, forceCSR, nonce, ssrRender, metaName = "modern-js" }) => async function render({ ctx, route, runner }) {
|
|
11
11
|
if (ctx.resHasHandled()) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
@@ -68,3 +68,6 @@ export const createRenderHandler = ({ distDir, staticGenerate, conf, forceCSR, n
|
|
|
68
68
|
contentType: mime.contentType(path.extname(templatePath))
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
export {
|
|
72
|
+
createRenderHandler
|
|
73
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { headersWithoutCookie } from "../../utils";
|
|
2
|
-
|
|
2
|
+
const createMetrics = (context, metrics) => {
|
|
3
3
|
const { entryName: entry, request } = context;
|
|
4
4
|
const { pathname = "" } = request || {};
|
|
5
5
|
const emitTimer = (name, cost, tags = {}) => {
|
|
@@ -21,7 +21,7 @@ export const createMetrics = (context, metrics) => {
|
|
|
21
21
|
emitCounter
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
const createLogger = (serverContext, logger) => {
|
|
25
25
|
const request = serverContext.request || {};
|
|
26
26
|
const { headers = {}, pathname = "" } = request;
|
|
27
27
|
const debug = (message, ...args) => {
|
|
@@ -43,3 +43,7 @@ export const createLogger = (serverContext, logger) => {
|
|
|
43
43
|
debug
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
+
export {
|
|
47
|
+
createLogger,
|
|
48
|
+
createMetrics
|
|
49
|
+
};
|
|
@@ -11,7 +11,7 @@ const createCacheItem = async (content, mtime) => {
|
|
|
11
11
|
mtime
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
class LruReader {
|
|
15
15
|
init(fs) {
|
|
16
16
|
this.fs = fs || extraFS;
|
|
17
17
|
}
|
|
@@ -71,16 +71,23 @@ export class LruReader {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
const reader = new LruReader();
|
|
74
|
-
|
|
74
|
+
const readFile = async (filepath) => {
|
|
75
75
|
const file = await reader.read(filepath);
|
|
76
76
|
return file === null || file === void 0 ? void 0 : file.content;
|
|
77
77
|
};
|
|
78
|
-
|
|
78
|
+
const updateFile = () => {
|
|
79
79
|
reader.update();
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
const init = (fs) => {
|
|
82
82
|
reader.init(fs);
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
const close = () => {
|
|
85
85
|
reader.close();
|
|
86
86
|
};
|
|
87
|
+
export {
|
|
88
|
+
LruReader,
|
|
89
|
+
close,
|
|
90
|
+
init,
|
|
91
|
+
readFile,
|
|
92
|
+
updateFile
|
|
93
|
+
};
|
|
@@ -3,7 +3,7 @@ import { fs, mime, LOADABLE_STATS_FILE, ROUTE_MANIFEST_FILE, SERVER_RENDER_FUNCT
|
|
|
3
3
|
import cache from "./cache";
|
|
4
4
|
import { createLogger, createMetrics } from "./measure";
|
|
5
5
|
import { injectServerDataStream, injectServerData } from "./utils";
|
|
6
|
-
|
|
6
|
+
const render = async (ctx, renderOptions, runner) => {
|
|
7
7
|
var _ctx_res;
|
|
8
8
|
const { urlPath, bundle, distDir, template, entryName, staticGenerate, enableUnsafeCtx = false, nonce } = renderOptions;
|
|
9
9
|
const bundleJS = path.join(distDir, bundle);
|
|
@@ -73,3 +73,6 @@ export const render = async (ctx, renderOptions, runner) => {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
+
export {
|
|
77
|
+
render
|
|
78
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { mime } from "@modern-js/utils";
|
|
3
3
|
import { readFile } from "./reader";
|
|
4
|
-
|
|
4
|
+
async function handleDirectory(ctx, entryPath, urlPath) {
|
|
5
5
|
const { path: pathname } = ctx;
|
|
6
6
|
const filepath = path.join(entryPath, trimLeft(pathname, urlPath));
|
|
7
7
|
let content = await readFile(filepath);
|
|
@@ -33,3 +33,6 @@ const trimLeft = (str, prefix) => {
|
|
|
33
33
|
}
|
|
34
34
|
return str;
|
|
35
35
|
};
|
|
36
|
+
export {
|
|
37
|
+
handleDirectory
|
|
38
|
+
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
var RenderLevel;
|
|
2
2
|
(function(RenderLevel2) {
|
|
3
3
|
RenderLevel2[RenderLevel2["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
|
|
4
4
|
RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
|
|
5
5
|
RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
|
|
6
6
|
})(RenderLevel || (RenderLevel = {}));
|
|
7
|
+
export {
|
|
8
|
+
RenderLevel
|
|
9
|
+
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { TemplateAPI } from "../hook-api/template";
|
|
2
2
|
import { templateInjectableStream } from "../hook-api/templateForStream";
|
|
3
|
-
|
|
3
|
+
const injectServerData = (content, context) => {
|
|
4
4
|
const template = new TemplateAPI(content);
|
|
5
5
|
template.prependHead(`<script type="application/json" id="__MODERN_SERVER_DATA__">${JSON.stringify(context.serverData)}</script>`);
|
|
6
6
|
return template.get();
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const injectServerDataStream = (content, context) => {
|
|
9
9
|
return content.pipe(templateInjectableStream({
|
|
10
10
|
prependHead: `<script type="application/json" id="__MODERN_SERVER_DATA__">${JSON.stringify(context.serverData)}</script>`
|
|
11
11
|
}));
|
|
12
12
|
};
|
|
13
|
+
export {
|
|
14
|
+
injectServerData,
|
|
15
|
+
injectServerDataStream
|
|
16
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { RouteMatcher } from "./matcher";
|
|
3
|
-
|
|
3
|
+
class RouteMatchManager {
|
|
4
4
|
// get all routes matches pathname
|
|
5
5
|
filter(pathname) {
|
|
6
6
|
return this.matchers.reduce((matches, matcher) => {
|
|
@@ -54,4 +54,7 @@ export class RouteMatchManager {
|
|
|
54
54
|
this.matchers = [];
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
export {
|
|
57
|
+
export {
|
|
58
|
+
RouteMatchManager,
|
|
59
|
+
RouteMatcher
|
|
60
|
+
};
|