@modern-js/prod-server 2.9.1-alpha.0 → 2.10.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/CHANGELOG.md +25 -0
- package/dist/cjs/libs/hook-api/index.js +7 -26
- package/dist/cjs/libs/render/index.js +2 -1
- package/dist/cjs/libs/render/ssr.js +3 -2
- package/dist/{js/node/libs/metrics.js → cjs/libs/render/utils.js} +25 -12
- package/dist/cjs/server/index.js +1 -1
- package/dist/cjs/server/modernServer.js +75 -80
- package/dist/esm/libs/hook-api/index.js +9 -37
- package/dist/esm/libs/render/index.js +2 -1
- package/dist/esm/libs/render/ssr.js +3 -2
- package/dist/esm/libs/render/utils.js +12 -0
- package/dist/esm/server/index.js +2 -2
- package/dist/esm/server/modernServer.js +108 -103
- package/dist/esm-node/libs/hook-api/index.js +7 -26
- package/dist/esm-node/libs/render/index.js +2 -1
- package/dist/esm-node/libs/render/ssr.js +3 -2
- package/dist/esm-node/libs/render/utils.js +23 -0
- package/dist/esm-node/server/index.js +1 -1
- package/dist/esm-node/server/modernServer.js +75 -80
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/utils.d.ts +5 -0
- package/dist/types/server/index.d.ts +2 -1
- package/dist/types/server/modernServer.d.ts +4 -4
- package/dist/types/type.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -7
- package/dist/js/modern/constants.js +0 -35
- package/dist/js/modern/index.js +0 -18
- package/dist/js/modern/libs/context/context.js +0 -160
- package/dist/js/modern/libs/context/index.js +0 -6
- package/dist/js/modern/libs/hook-api/index.js +0 -134
- package/dist/js/modern/libs/hook-api/route.js +0 -20
- package/dist/js/modern/libs/hook-api/template.js +0 -73
- package/dist/js/modern/libs/loadConfig.js +0 -62
- package/dist/js/modern/libs/logger.js +0 -111
- package/dist/js/modern/libs/metrics.js +0 -11
- package/dist/js/modern/libs/proxy.js +0 -92
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
- package/dist/js/modern/libs/render/cache/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
- package/dist/js/modern/libs/render/cache/spr.js +0 -248
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +0 -102
- package/dist/js/modern/libs/render/index.js +0 -86
- package/dist/js/modern/libs/render/measure.js +0 -68
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/ssr.js +0 -100
- package/dist/js/modern/libs/render/static.js +0 -60
- package/dist/js/modern/libs/render/type.js +0 -9
- package/dist/js/modern/libs/route/index.js +0 -54
- package/dist/js/modern/libs/route/matcher.js +0 -87
- package/dist/js/modern/libs/route/route.js +0 -16
- package/dist/js/modern/libs/serve-file.js +0 -67
- package/dist/js/modern/server/index.js +0 -208
- package/dist/js/modern/server/modern-server-split.js +0 -74
- package/dist/js/modern/server/modern-server.js +0 -554
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +0 -136
- package/dist/js/modern/worker-server.js +0 -89
- package/dist/js/node/constants.js +0 -62
- package/dist/js/node/index.js +0 -44
- package/dist/js/node/libs/context/context.js +0 -189
- package/dist/js/node/libs/context/index.js +0 -30
- package/dist/js/node/libs/hook-api/index.js +0 -164
- package/dist/js/node/libs/hook-api/route.js +0 -43
- package/dist/js/node/libs/hook-api/template.js +0 -97
- package/dist/js/node/libs/loadConfig.js +0 -91
- package/dist/js/node/libs/logger.js +0 -133
- package/dist/js/node/libs/proxy.js +0 -114
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
- package/dist/js/node/libs/render/cache/index.js +0 -134
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
- package/dist/js/node/libs/render/cache/spr.js +0 -270
- package/dist/js/node/libs/render/cache/type.js +0 -15
- package/dist/js/node/libs/render/cache/util.js +0 -138
- package/dist/js/node/libs/render/index.js +0 -115
- package/dist/js/node/libs/render/measure.js +0 -90
- package/dist/js/node/libs/render/reader.js +0 -140
- package/dist/js/node/libs/render/ssr.js +0 -123
- package/dist/js/node/libs/render/static.js +0 -89
- package/dist/js/node/libs/render/type.js +0 -32
- package/dist/js/node/libs/route/index.js +0 -78
- package/dist/js/node/libs/route/matcher.js +0 -106
- package/dist/js/node/libs/route/route.js +0 -39
- package/dist/js/node/libs/serve-file.js +0 -97
- package/dist/js/node/server/index.js +0 -219
- package/dist/js/node/server/modern-server-split.js +0 -97
- package/dist/js/node/server/modern-server.js +0 -559
- package/dist/js/node/type.js +0 -15
- package/dist/js/node/utils.js +0 -166
- package/dist/js/node/worker-server.js +0 -113
- package/dist/js/treeshaking/constants.js +0 -29
- package/dist/js/treeshaking/index.js +0 -13
- package/dist/js/treeshaking/libs/context/context.js +0 -274
- package/dist/js/treeshaking/libs/context/index.js +0 -5
- package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
- package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
- package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
- package/dist/js/treeshaking/libs/loadConfig.js +0 -82
- package/dist/js/treeshaking/libs/logger.js +0 -205
- package/dist/js/treeshaking/libs/metrics.js +0 -6
- package/dist/js/treeshaking/libs/proxy.js +0 -244
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
- package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
- package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
- package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
- package/dist/js/treeshaking/libs/render/index.js +0 -234
- package/dist/js/treeshaking/libs/render/measure.js +0 -146
- package/dist/js/treeshaking/libs/render/reader.js +0 -339
- package/dist/js/treeshaking/libs/render/ssr.js +0 -223
- package/dist/js/treeshaking/libs/render/static.js +0 -216
- package/dist/js/treeshaking/libs/render/type.js +0 -7
- package/dist/js/treeshaking/libs/route/index.js +0 -130
- package/dist/js/treeshaking/libs/route/matcher.js +0 -143
- package/dist/js/treeshaking/libs/route/route.js +0 -40
- package/dist/js/treeshaking/libs/serve-file.js +0 -184
- package/dist/js/treeshaking/server/index.js +0 -505
- package/dist/js/treeshaking/server/modern-server-split.js +0 -360
- package/dist/js/treeshaking/server/modern-server.js +0 -1089
- package/dist/js/treeshaking/type.js +0 -1
- package/dist/js/treeshaking/utils.js +0 -147
- package/dist/js/treeshaking/worker-server.js +0 -233
package/dist/js/node/utils.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
-
};
|
|
23
|
-
var __copyProps = (to, from, except, desc) => {
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
-
for (let key of __getOwnPropNames(from))
|
|
26
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
-
}
|
|
29
|
-
return to;
|
|
30
|
-
};
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
var utils_exports = {};
|
|
33
|
-
__export(utils_exports, {
|
|
34
|
-
createErrorDocument: () => createErrorDocument,
|
|
35
|
-
createMiddlewareCollecter: () => createMiddlewareCollecter,
|
|
36
|
-
debug: () => debug,
|
|
37
|
-
getStaticReg: () => getStaticReg,
|
|
38
|
-
headersWithoutCookie: () => headersWithoutCookie,
|
|
39
|
-
isRedirect: () => isRedirect,
|
|
40
|
-
mergeExtension: () => mergeExtension,
|
|
41
|
-
noop: () => noop,
|
|
42
|
-
prepareFavicons: () => prepareFavicons,
|
|
43
|
-
useLocalPrefix: () => useLocalPrefix
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(utils_exports);
|
|
46
|
-
var import_utils = require("@modern-js/utils");
|
|
47
|
-
const debug = (0, import_utils.createDebugger)("prod-server");
|
|
48
|
-
const mergeExtension = (users) => {
|
|
49
|
-
const output = [];
|
|
50
|
-
return { middleware: output.concat(users) };
|
|
51
|
-
};
|
|
52
|
-
const noop = () => {
|
|
53
|
-
};
|
|
54
|
-
const createErrorDocument = (status, text) => {
|
|
55
|
-
const title = `${status}: ${text}`;
|
|
56
|
-
return `<!DOCTYPE html>
|
|
57
|
-
<html lang="en">
|
|
58
|
-
<head>
|
|
59
|
-
<meta charset="utf-8">
|
|
60
|
-
<meta name="viewport" content="width=device-width">
|
|
61
|
-
<title>${title}</title>
|
|
62
|
-
<style>
|
|
63
|
-
html,body {
|
|
64
|
-
margin: 0;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.page-container {
|
|
68
|
-
color: #000;
|
|
69
|
-
background: #fff;
|
|
70
|
-
height: 100vh;
|
|
71
|
-
text-align: center;
|
|
72
|
-
display: flex;
|
|
73
|
-
flex-direction: column;
|
|
74
|
-
align-items: center;
|
|
75
|
-
justify-content: center;
|
|
76
|
-
}
|
|
77
|
-
</style>
|
|
78
|
-
</head>
|
|
79
|
-
<body>
|
|
80
|
-
<div class="page-container">
|
|
81
|
-
<h1>${status}</h1>
|
|
82
|
-
<div>${text}</div>
|
|
83
|
-
</body>
|
|
84
|
-
</html>
|
|
85
|
-
`;
|
|
86
|
-
};
|
|
87
|
-
const createMiddlewareCollecter = () => {
|
|
88
|
-
const webMiddlewares = [];
|
|
89
|
-
const apiMiddlewares = [];
|
|
90
|
-
const addWebMiddleware = (input) => {
|
|
91
|
-
webMiddlewares.push(input);
|
|
92
|
-
};
|
|
93
|
-
const addAPIMiddleware = (input) => {
|
|
94
|
-
apiMiddlewares.push(input);
|
|
95
|
-
};
|
|
96
|
-
const getMiddlewares = () => ({
|
|
97
|
-
web: webMiddlewares,
|
|
98
|
-
api: apiMiddlewares
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
getMiddlewares,
|
|
102
|
-
addWebMiddleware,
|
|
103
|
-
addAPIMiddleware
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const useLocalPrefix = (url) => {
|
|
107
|
-
return (0, import_utils.isProd)() && !url.includes(".");
|
|
108
|
-
};
|
|
109
|
-
const getStaticReg = (output = {}, html = {}) => {
|
|
110
|
-
const {
|
|
111
|
-
distPath: { css: cssPath, js: jsPath, media: mediaPath } = {},
|
|
112
|
-
assetPrefix = "/"
|
|
113
|
-
} = output;
|
|
114
|
-
const { favicon, faviconByEntries } = html;
|
|
115
|
-
const prefix = useLocalPrefix(assetPrefix) ? assetPrefix : "";
|
|
116
|
-
const favicons = prepareFavicons(favicon, faviconByEntries);
|
|
117
|
-
const staticFiles = [cssPath, jsPath, mediaPath].filter((v) => Boolean(v));
|
|
118
|
-
const staticReg = ["static/", "upload/", ...staticFiles];
|
|
119
|
-
const iconReg = ["favicon.ico", "icon.png", ...favicons];
|
|
120
|
-
const regPrefix = prefix.endsWith("/") ? prefix : `${prefix}/`;
|
|
121
|
-
const staticPathRegExp = new RegExp(
|
|
122
|
-
`^${regPrefix}(${[...staticReg, ...iconReg].join("|")})`
|
|
123
|
-
);
|
|
124
|
-
return staticPathRegExp;
|
|
125
|
-
};
|
|
126
|
-
const prepareFavicons = (favicon, faviconByEntries) => {
|
|
127
|
-
const faviconNames = [];
|
|
128
|
-
if (favicon) {
|
|
129
|
-
faviconNames.push(favicon.substring(favicon.lastIndexOf("/") + 1));
|
|
130
|
-
}
|
|
131
|
-
if (faviconByEntries) {
|
|
132
|
-
Object.keys(faviconByEntries).forEach((f) => {
|
|
133
|
-
const curFavicon = faviconByEntries[f];
|
|
134
|
-
if (curFavicon) {
|
|
135
|
-
faviconNames.push(
|
|
136
|
-
curFavicon.substring(curFavicon.lastIndexOf("/") + 1)
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return faviconNames;
|
|
142
|
-
};
|
|
143
|
-
const headersWithoutCookie = (headers) => {
|
|
144
|
-
if (typeof headers.cookie !== "undefined") {
|
|
145
|
-
const safeHeaders = __spreadValues({}, headers);
|
|
146
|
-
delete safeHeaders.cookie;
|
|
147
|
-
return safeHeaders;
|
|
148
|
-
}
|
|
149
|
-
return headers;
|
|
150
|
-
};
|
|
151
|
-
const isRedirect = (code) => {
|
|
152
|
-
return [301, 302, 307, 308].includes(code);
|
|
153
|
-
};
|
|
154
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
-
0 && (module.exports = {
|
|
156
|
-
createErrorDocument,
|
|
157
|
-
createMiddlewareCollecter,
|
|
158
|
-
debug,
|
|
159
|
-
getStaticReg,
|
|
160
|
-
headersWithoutCookie,
|
|
161
|
-
isRedirect,
|
|
162
|
-
mergeExtension,
|
|
163
|
-
noop,
|
|
164
|
-
prepareFavicons,
|
|
165
|
-
useLocalPrefix
|
|
166
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var worker_server_exports = {};
|
|
39
|
-
__export(worker_server_exports, {
|
|
40
|
-
createHandler: () => createHandler,
|
|
41
|
-
handleUrl: () => handleUrl
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(worker_server_exports);
|
|
44
|
-
var import_logger = require("./libs/logger");
|
|
45
|
-
var import_route = require("./libs/route");
|
|
46
|
-
var import_metrics = require("./libs/metrics");
|
|
47
|
-
const handleUrl = (url) => {
|
|
48
|
-
return url.replace(/^https?:\/\/.*?\//gi, "/");
|
|
49
|
-
};
|
|
50
|
-
const createHandler = (manifest) => {
|
|
51
|
-
const routeMgr = new import_route.RouteMatchManager();
|
|
52
|
-
const { pages, routes } = manifest;
|
|
53
|
-
routeMgr.reset(routes);
|
|
54
|
-
return (ctx) => __async(void 0, null, function* () {
|
|
55
|
-
var _a, _b, _c, _d, _e, _f;
|
|
56
|
-
const pageMatch = routeMgr.match(ctx.url);
|
|
57
|
-
if (!pageMatch) {
|
|
58
|
-
ctx.body = "404: Page not found";
|
|
59
|
-
ctx.status = 404;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const page = pages[pageMatch.spec.urlPath];
|
|
63
|
-
(_b = (_a = ctx.request).query) != null ? _b : _a.query = ctx.query;
|
|
64
|
-
(_d = (_c = ctx.request).pathname) != null ? _d : _c.pathname = ctx.pathname;
|
|
65
|
-
(_f = (_e = ctx.request).params) != null ? _f : _e.params = ctx.params;
|
|
66
|
-
const params = pageMatch.parseURLParams(ctx.url);
|
|
67
|
-
if (page.serverRender) {
|
|
68
|
-
try {
|
|
69
|
-
ctx.body = yield page.serverRender({
|
|
70
|
-
entryName: page.entryName,
|
|
71
|
-
template: page.template,
|
|
72
|
-
query: ctx.query,
|
|
73
|
-
request: ctx.request,
|
|
74
|
-
response: ctx.response,
|
|
75
|
-
pathname: ctx.pathname,
|
|
76
|
-
req: ctx.request,
|
|
77
|
-
res: ctx.response,
|
|
78
|
-
params: ctx.params || params || {},
|
|
79
|
-
logger: ctx.logger || new import_logger.Logger({
|
|
80
|
-
level: "warn"
|
|
81
|
-
}),
|
|
82
|
-
metrics: ctx.metrics || import_metrics.metrics,
|
|
83
|
-
loadableStats: ctx.loadableStats,
|
|
84
|
-
routeManifest: ctx.routeManifest
|
|
85
|
-
});
|
|
86
|
-
ctx.status = 200;
|
|
87
|
-
return;
|
|
88
|
-
} catch (e) {
|
|
89
|
-
if (page.template) {
|
|
90
|
-
ctx.body = page.template;
|
|
91
|
-
ctx.status = 200;
|
|
92
|
-
return;
|
|
93
|
-
} else {
|
|
94
|
-
ctx.body = "404: not found";
|
|
95
|
-
ctx.status = 404;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (page.template) {
|
|
101
|
-
ctx.body = page.template;
|
|
102
|
-
ctx.status = 200;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
ctx.body = "404: not found";
|
|
106
|
-
ctx.status = 404;
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
-
0 && (module.exports = {
|
|
111
|
-
createHandler,
|
|
112
|
-
handleUrl
|
|
113
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var AGGRED_DIR = {
|
|
2
|
-
mock: "config/mock",
|
|
3
|
-
server: "server",
|
|
4
|
-
api: "api",
|
|
5
|
-
shared: "shared",
|
|
6
|
-
lambda: "lambda"
|
|
7
|
-
};
|
|
8
|
-
var ApiServerMode = /* @__PURE__ */ function(ApiServerMode2) {
|
|
9
|
-
ApiServerMode2["func"] = "function";
|
|
10
|
-
ApiServerMode2["frame"] = "framework";
|
|
11
|
-
return ApiServerMode2;
|
|
12
|
-
}(ApiServerMode || {});
|
|
13
|
-
var ERROR_DIGEST = {
|
|
14
|
-
INIT: "Server init error",
|
|
15
|
-
ENOTF: "Page could not be found",
|
|
16
|
-
WARMUP: "SSR warmup failed",
|
|
17
|
-
EINTER: "Internal server error",
|
|
18
|
-
ERENDER: "SSR render failed",
|
|
19
|
-
EMICROINJ: "Get micro-frontend info failed"
|
|
20
|
-
};
|
|
21
|
-
var ERROR_PAGE_TEXT = {
|
|
22
|
-
404: "This page could not be found.",
|
|
23
|
-
500: "Internal Server Error."
|
|
24
|
-
};
|
|
25
|
-
var RUN_MODE = {
|
|
26
|
-
FULL: "full",
|
|
27
|
-
TYPE: "type"
|
|
28
|
-
};
|
|
29
|
-
export { AGGRED_DIR, ApiServerMode, ERROR_DIGEST, ERROR_PAGE_TEXT, RUN_MODE };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Server } from "./server";
|
|
2
|
-
import { ModernServer } from "./server/modern-server";
|
|
3
|
-
import { createProxyHandler } from "./libs/proxy";
|
|
4
|
-
export * from "./type";
|
|
5
|
-
export * from "./constants";
|
|
6
|
-
var src_default = function(options) {
|
|
7
|
-
if (options == null) {
|
|
8
|
-
throw new Error("can not start mserver without options");
|
|
9
|
-
}
|
|
10
|
-
var server = new Server(options);
|
|
11
|
-
return server.init();
|
|
12
|
-
};
|
|
13
|
-
export { ModernServer, Server, createProxyHandler, src_default as default };
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) {
|
|
2
|
-
if (!(instance instanceof Constructor)) {
|
|
3
|
-
throw new TypeError("Cannot call a class as a function");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
function _defineProperties(target, props) {
|
|
7
|
-
for(var i = 0; i < props.length; i++){
|
|
8
|
-
var descriptor = props[i];
|
|
9
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
-
descriptor.configurable = true;
|
|
11
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
-
return Constructor;
|
|
19
|
-
}
|
|
20
|
-
function _defineProperty(obj, key, value) {
|
|
21
|
-
if (key in obj) {
|
|
22
|
-
Object.defineProperty(obj, key, {
|
|
23
|
-
value: value,
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
obj[key] = value;
|
|
30
|
-
}
|
|
31
|
-
return obj;
|
|
32
|
-
}
|
|
33
|
-
function _instanceof(left, right) {
|
|
34
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
35
|
-
return !!right[Symbol.hasInstance](left);
|
|
36
|
-
} else {
|
|
37
|
-
return left instanceof right;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
import { URL } from "url";
|
|
41
|
-
import qs from "querystring";
|
|
42
|
-
import { Buffer } from "buffer";
|
|
43
|
-
import createEtag from "etag";
|
|
44
|
-
import fresh from "fresh";
|
|
45
|
-
import { headersWithoutCookie } from "../../utils";
|
|
46
|
-
var ModernServerContext = /*#__PURE__*/ function() {
|
|
47
|
-
"use strict";
|
|
48
|
-
function ModernServerContext(req, res, options) {
|
|
49
|
-
_classCallCheck(this, ModernServerContext);
|
|
50
|
-
_defineProperty(this, "req", void 0);
|
|
51
|
-
_defineProperty(this, "res", void 0);
|
|
52
|
-
_defineProperty(this, "params", {});
|
|
53
|
-
_defineProperty(this, "serverData", void 0);
|
|
54
|
-
_defineProperty(this, "options", {});
|
|
55
|
-
this.req = req;
|
|
56
|
-
this.res = res;
|
|
57
|
-
this.options = options || {};
|
|
58
|
-
this.serverData = {};
|
|
59
|
-
this.bind();
|
|
60
|
-
}
|
|
61
|
-
_createClass(ModernServerContext, [
|
|
62
|
-
{
|
|
63
|
-
key: "logger",
|
|
64
|
-
get: function get() {
|
|
65
|
-
return this.req.logger;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
key: "metrics",
|
|
70
|
-
get: function get() {
|
|
71
|
-
return this.req.metrics;
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
key: "bind",
|
|
76
|
-
value: function bind() {
|
|
77
|
-
var _this = this;
|
|
78
|
-
var _this1 = this, req = _this1.req, res = _this1.res;
|
|
79
|
-
req.get = function(key) {
|
|
80
|
-
return _this.getReqHeader(key);
|
|
81
|
-
};
|
|
82
|
-
res.set = function(key, value) {
|
|
83
|
-
return _this.res.setHeader(key, value);
|
|
84
|
-
};
|
|
85
|
-
res.send = function(body) {
|
|
86
|
-
_this.send(body);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
key: "send",
|
|
92
|
-
value: function send(body) {
|
|
93
|
-
try {
|
|
94
|
-
var generateETag = !this.res.getHeader("ETag") && this.options.etag;
|
|
95
|
-
if (body !== void 0 && generateETag) {
|
|
96
|
-
var encoding = typeof body === "string" ? "utf-8" : void 0;
|
|
97
|
-
var buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
|
|
98
|
-
var etag = createEtag(buf, {
|
|
99
|
-
weak: true
|
|
100
|
-
});
|
|
101
|
-
if (etag) {
|
|
102
|
-
this.res.setHeader("ETag", etag);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (this.fresh) {
|
|
106
|
-
this.status = 304;
|
|
107
|
-
}
|
|
108
|
-
} catch (e) {
|
|
109
|
-
this.logger.error(e.message);
|
|
110
|
-
}
|
|
111
|
-
this.res.end(body);
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
key: "setParams",
|
|
116
|
-
value: function setParams(params) {
|
|
117
|
-
this.params = params;
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
key: "setServerData",
|
|
122
|
-
value: function setServerData(key, value) {
|
|
123
|
-
this.serverData[key] = value;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
key: "getReqHeader",
|
|
128
|
-
value: function getReqHeader(key) {
|
|
129
|
-
var req = this.req;
|
|
130
|
-
var field = key.toLowerCase();
|
|
131
|
-
switch(field){
|
|
132
|
-
case "referer":
|
|
133
|
-
case "referrer":
|
|
134
|
-
return req.headers.referrer || req.headers.referer || "";
|
|
135
|
-
default:
|
|
136
|
-
return req.headers[field] || "";
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
key: "fresh",
|
|
142
|
-
get: function get() {
|
|
143
|
-
var _this = this, status = _this.status, res = _this.res, method = _this.method;
|
|
144
|
-
if ("GET" !== method && "HEAD" !== method) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
if (status >= 200 && status < 300 || 304 === status) {
|
|
148
|
-
return fresh(this.headers, {
|
|
149
|
-
etag: res.getHeader("ETag"),
|
|
150
|
-
"last-modified": res.getHeader("Last-Modified")
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
key: "headers",
|
|
158
|
-
get: function get() {
|
|
159
|
-
return this.req.headers;
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
key: "method",
|
|
164
|
-
get: function get() {
|
|
165
|
-
return this.req.method;
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
key: "url",
|
|
170
|
-
get: function get() {
|
|
171
|
-
return this.req.url || "";
|
|
172
|
-
},
|
|
173
|
-
set: function set(val) {
|
|
174
|
-
this.req.url = val;
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
key: "host",
|
|
179
|
-
get: function get() {
|
|
180
|
-
var host = this.getReqHeader("X-Forwarded-Host");
|
|
181
|
-
if (!host) {
|
|
182
|
-
host = this.getReqHeader("Host");
|
|
183
|
-
}
|
|
184
|
-
return host.split(/\s*,\s*/, 1)[0] || "";
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
key: "protocol",
|
|
189
|
-
get: function get() {
|
|
190
|
-
if (this.req.socket.encrypted) {
|
|
191
|
-
return "https";
|
|
192
|
-
}
|
|
193
|
-
var proto = this.getReqHeader("X-Forwarded-Proto");
|
|
194
|
-
return proto ? proto.split(/\s*,\s*/, 1)[0] : "http";
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
key: "origin",
|
|
199
|
-
get: function get() {
|
|
200
|
-
return "".concat(this.protocol, "://").concat(this.host);
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
key: "href",
|
|
205
|
-
get: function get() {
|
|
206
|
-
return this.origin + this.url;
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
key: "parsedURL",
|
|
211
|
-
get: function get() {
|
|
212
|
-
var url = new URL(this.req.url, this.origin);
|
|
213
|
-
return url;
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
key: "path",
|
|
218
|
-
get: function get() {
|
|
219
|
-
return this.parsedURL.pathname;
|
|
220
|
-
},
|
|
221
|
-
set: function set(p) {
|
|
222
|
-
var url = new URL(this.req.url, this.origin);
|
|
223
|
-
if (!url || !p) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (url.pathname === p) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
url.pathname = p;
|
|
230
|
-
this.url = url.toString();
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
key: "querystring",
|
|
235
|
-
get: function get() {
|
|
236
|
-
if (!this.req) {
|
|
237
|
-
return "";
|
|
238
|
-
}
|
|
239
|
-
return this.parsedURL.search.replace(/^\?/, "") || "";
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
key: "query",
|
|
244
|
-
get: function get() {
|
|
245
|
-
var str = this.querystring;
|
|
246
|
-
return qs.parse(str);
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
key: "status",
|
|
251
|
-
get: function get() {
|
|
252
|
-
return this.res.statusCode;
|
|
253
|
-
},
|
|
254
|
-
set: function set(statusCode) {
|
|
255
|
-
this.res.statusCode = statusCode;
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
key: "resHasHandled",
|
|
260
|
-
value: function resHasHandled() {
|
|
261
|
-
return this.res.writableEnded;
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
key: "error",
|
|
266
|
-
value: function error(dig) {
|
|
267
|
-
var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
268
|
-
this.logger.error("Web Server Error - ".concat(dig, ", error = %s, req.url = %s, req.headers = %o"), _instanceof(e, Error) ? e.stack || e.message : e, this.path, headersWithoutCookie(this.headers));
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
]);
|
|
272
|
-
return ModernServerContext;
|
|
273
|
-
}();
|
|
274
|
-
export { ModernServerContext };
|