@bleedingdev/modern-js-prod-server 3.2.0-ultramodern.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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/cjs/apply.js +97 -0
- package/dist/cjs/index.js +89 -0
- package/dist/cjs/libs/contractGateAutopilot.js +36 -0
- package/dist/cjs/libs/loadConfig.js +72 -0
- package/dist/cjs/libs/metrics.js +41 -0
- package/dist/cjs/libs/render/index.js +125 -0
- package/dist/cjs/libs/render/ssr.js +118 -0
- package/dist/cjs/libs/render/utils.js +72 -0
- package/dist/cjs/libs/runtimeFallbackWorkerLane.js +167 -0
- package/dist/cjs/libs/telemetry.js +87 -0
- package/dist/cjs/netlify.js +56 -0
- package/dist/cjs/server/index.js +579 -0
- package/dist/cjs/server/modernServer.js +472 -0
- package/dist/cjs/server/modernServerSplit.js +38 -0
- package/dist/cjs/types.js +18 -0
- package/dist/cjs/utils.js +38 -0
- package/dist/esm/apply.mjs +63 -0
- package/dist/esm/index.mjs +26 -0
- package/dist/esm/libs/contractGateAutopilot.mjs +1 -0
- package/dist/esm/libs/loadConfig.mjs +22 -0
- package/dist/esm/libs/metrics.mjs +7 -0
- package/dist/esm/libs/render/index.mjs +81 -0
- package/dist/esm/libs/render/ssr.mjs +73 -0
- package/dist/esm/libs/render/utils.mjs +35 -0
- package/dist/esm/libs/runtimeFallbackWorkerLane.mjs +130 -0
- package/dist/esm/libs/telemetry.mjs +1 -0
- package/dist/esm/netlify.mjs +22 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/server/index.mjs +535 -0
- package/dist/esm/server/modernServer.mjs +419 -0
- package/dist/esm/server/modernServerSplit.mjs +4 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/utils.mjs +4 -0
- package/dist/esm-node/apply.mjs +64 -0
- package/dist/esm-node/index.mjs +27 -0
- package/dist/esm-node/libs/contractGateAutopilot.mjs +2 -0
- package/dist/esm-node/libs/loadConfig.mjs +23 -0
- package/dist/esm-node/libs/metrics.mjs +8 -0
- package/dist/esm-node/libs/render/index.mjs +82 -0
- package/dist/esm-node/libs/render/ssr.mjs +75 -0
- package/dist/esm-node/libs/render/utils.mjs +36 -0
- package/dist/esm-node/libs/runtimeFallbackWorkerLane.mjs +131 -0
- package/dist/esm-node/libs/telemetry.mjs +2 -0
- package/dist/esm-node/netlify.mjs +23 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/esm-node/server/index.mjs +536 -0
- package/dist/esm-node/server/modernServer.mjs +421 -0
- package/dist/esm-node/server/modernServerSplit.mjs +5 -0
- package/dist/esm-node/types.mjs +1 -0
- package/dist/esm-node/utils.mjs +5 -0
- package/dist/types/apply.d.ts +6 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/libs/metrics.d.ts +8 -0
- package/dist/types/libs/telemetry.d.ts +2 -0
- package/dist/types/netlify.d.ts +3 -0
- package/dist/types/types.d.ts +15 -0
- package/package.json +79 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Modern.js Package
|
|
2
|
+
|
|
3
|
+
## Get Started
|
|
4
|
+
|
|
5
|
+
Run and debug the module:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm run dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Run test cases:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm run test
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Build the module for production:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Enable optional features:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm run new
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
For more information, see the [Modern.js Module documentation](https://modernjs.dev/module-tools/en).
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
applyPlugins: ()=>applyPlugins
|
|
28
|
+
});
|
|
29
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
30
|
+
const node_namespaceObject = require("@modern-js/server-core/node");
|
|
31
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
32
|
+
function getLogger(_) {
|
|
33
|
+
if (process.env.DEBUG || 'production' === process.env.NODE_ENV) return (0, utils_namespaceObject.createLogger)({
|
|
34
|
+
level: process.env.MODERN_SERVER_LOG_LEVEL || 'verbose'
|
|
35
|
+
});
|
|
36
|
+
return (0, utils_namespaceObject.createLogger)();
|
|
37
|
+
}
|
|
38
|
+
async function applyPlugins(serverBase, options, nodeServer) {
|
|
39
|
+
const { pwd, appContext, config, logger: optLogger, serverConfig } = options;
|
|
40
|
+
const enableRsc = config.server?.rsc ?? serverConfig?.server?.rsc ?? false;
|
|
41
|
+
const serverErrorHandler = options.serverConfig?.onError;
|
|
42
|
+
const loadCachePwd = (0, utils_namespaceObject.isProd)() ? pwd : appContext.appDirectory || pwd;
|
|
43
|
+
const cacheConfig = await (0, node_namespaceObject.loadCacheConfig)(loadCachePwd);
|
|
44
|
+
serverBase.notFound((c)=>{
|
|
45
|
+
const monitors = c.get('monitors');
|
|
46
|
+
(0, server_core_namespaceObject.onError)(server_core_namespaceObject.ErrorDigest.ENOTF, '404 not found', monitors, c.req.raw);
|
|
47
|
+
return c.html((0, server_core_namespaceObject.createErrorHtml)(404), 404);
|
|
48
|
+
});
|
|
49
|
+
serverBase.onError(async (err, c)=>{
|
|
50
|
+
const monitors = c.get('monitors');
|
|
51
|
+
(0, server_core_namespaceObject.onError)(server_core_namespaceObject.ErrorDigest.EINTER, err, monitors, c.req.raw);
|
|
52
|
+
if (serverErrorHandler) try {
|
|
53
|
+
const result = await serverErrorHandler(err, c);
|
|
54
|
+
if (result instanceof Response) return result;
|
|
55
|
+
} catch (configError) {
|
|
56
|
+
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
57
|
+
}
|
|
58
|
+
const bffPrefix = config.bff?.prefix || '/api';
|
|
59
|
+
const bffPrefixList = Array.isArray(bffPrefix) ? bffPrefix : [
|
|
60
|
+
bffPrefix
|
|
61
|
+
];
|
|
62
|
+
const isApiPath = bffPrefixList.some((prefix)=>c.req.path.startsWith(prefix));
|
|
63
|
+
if (isApiPath) return c.json({
|
|
64
|
+
message: err?.message || '[BFF] Internal Server Error'
|
|
65
|
+
}, err?.status || 500);
|
|
66
|
+
return c.html((0, server_core_namespaceObject.createErrorHtml)(500), 500);
|
|
67
|
+
});
|
|
68
|
+
const loggerOptions = config.server.logger;
|
|
69
|
+
const { middlewares, renderMiddlewares } = options.serverConfig || {};
|
|
70
|
+
const plugins = [
|
|
71
|
+
...nodeServer ? [
|
|
72
|
+
(0, node_namespaceObject.injectNodeSeverPlugin)({
|
|
73
|
+
nodeServer
|
|
74
|
+
})
|
|
75
|
+
] : [],
|
|
76
|
+
...(0, server_core_namespaceObject.createDefaultPlugins)({
|
|
77
|
+
cacheConfig,
|
|
78
|
+
staticGenerate: options.staticGenerate,
|
|
79
|
+
logger: false === loggerOptions ? false : optLogger || getLogger(loggerOptions)
|
|
80
|
+
}),
|
|
81
|
+
(0, server_core_namespaceObject.injectConfigMiddlewarePlugin)(middlewares, renderMiddlewares),
|
|
82
|
+
...options.plugins || [],
|
|
83
|
+
(0, node_namespaceObject.injectResourcePlugin)(),
|
|
84
|
+
(0, node_namespaceObject.injectRscManifestPlugin)(enableRsc),
|
|
85
|
+
(0, node_namespaceObject.serverStaticPlugin)(),
|
|
86
|
+
(0, server_core_namespaceObject.faviconPlugin)(),
|
|
87
|
+
(0, server_core_namespaceObject.renderPlugin)()
|
|
88
|
+
];
|
|
89
|
+
serverBase.addPlugins(plugins);
|
|
90
|
+
}
|
|
91
|
+
exports.applyPlugins = __webpack_exports__.applyPlugins;
|
|
92
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
93
|
+
"applyPlugins"
|
|
94
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
95
|
+
Object.defineProperty(exports, '__esModule', {
|
|
96
|
+
value: true
|
|
97
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
TelemetryCanaryOrchestrator: ()=>telemetry_js_namespaceObject.TelemetryCanaryOrchestrator,
|
|
28
|
+
TelemetryRegistry: ()=>telemetry_js_namespaceObject.TelemetryRegistry,
|
|
29
|
+
TelemetryStartupHealthError: ()=>telemetry_js_namespaceObject.TelemetryStartupHealthError,
|
|
30
|
+
applyPlugins: ()=>external_apply_js_namespaceObject.applyPlugins,
|
|
31
|
+
createOtlpTelemetryExporter: ()=>telemetry_js_namespaceObject.createOtlpTelemetryExporter,
|
|
32
|
+
createProdServer: ()=>createProdServer,
|
|
33
|
+
createTelemetryAwareMetrics: ()=>telemetry_js_namespaceObject.createTelemetryAwareMetrics,
|
|
34
|
+
createVictoriaMetricsTelemetryExporter: ()=>telemetry_js_namespaceObject.createVictoriaMetricsTelemetryExporter,
|
|
35
|
+
default: ()=>src,
|
|
36
|
+
hasEnabledTelemetryExporters: ()=>telemetry_js_namespaceObject.hasEnabledTelemetryExporters,
|
|
37
|
+
loadServerPlugins: ()=>node_namespaceObject.loadServerPlugins
|
|
38
|
+
});
|
|
39
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
40
|
+
const node_namespaceObject = require("@modern-js/server-core/node");
|
|
41
|
+
const external_apply_js_namespaceObject = require("./apply.js");
|
|
42
|
+
const telemetry_js_namespaceObject = require("./libs/telemetry.js");
|
|
43
|
+
const createProdServer = async (options)=>{
|
|
44
|
+
await (0, node_namespaceObject.loadServerEnv)(options);
|
|
45
|
+
const serverBaseOptions = options;
|
|
46
|
+
const serverCliConfig = 'production' === process.env.NODE_ENV ? (0, node_namespaceObject.loadServerCliConfig)(options.pwd, options.config) : options.config;
|
|
47
|
+
if (serverCliConfig) serverBaseOptions.config = serverCliConfig;
|
|
48
|
+
const serverRuntimeConfig = await (0, node_namespaceObject.loadServerRuntimeConfig)(options.serverConfigPath);
|
|
49
|
+
if (serverRuntimeConfig) {
|
|
50
|
+
serverBaseOptions.serverConfig = serverRuntimeConfig;
|
|
51
|
+
serverBaseOptions.plugins = [
|
|
52
|
+
...serverRuntimeConfig.plugins || [],
|
|
53
|
+
...options.plugins || []
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
const server = (0, server_core_namespaceObject.createServerBase)(serverBaseOptions);
|
|
57
|
+
const nodeServer = await (0, node_namespaceObject.createNodeServer)(server.handle.bind(server));
|
|
58
|
+
await (0, external_apply_js_namespaceObject.applyPlugins)(server, options, nodeServer);
|
|
59
|
+
await server.init();
|
|
60
|
+
return nodeServer;
|
|
61
|
+
};
|
|
62
|
+
const src = createProdServer;
|
|
63
|
+
exports.TelemetryCanaryOrchestrator = __webpack_exports__.TelemetryCanaryOrchestrator;
|
|
64
|
+
exports.TelemetryRegistry = __webpack_exports__.TelemetryRegistry;
|
|
65
|
+
exports.TelemetryStartupHealthError = __webpack_exports__.TelemetryStartupHealthError;
|
|
66
|
+
exports.applyPlugins = __webpack_exports__.applyPlugins;
|
|
67
|
+
exports.createOtlpTelemetryExporter = __webpack_exports__.createOtlpTelemetryExporter;
|
|
68
|
+
exports.createProdServer = __webpack_exports__.createProdServer;
|
|
69
|
+
exports.createTelemetryAwareMetrics = __webpack_exports__.createTelemetryAwareMetrics;
|
|
70
|
+
exports.createVictoriaMetricsTelemetryExporter = __webpack_exports__.createVictoriaMetricsTelemetryExporter;
|
|
71
|
+
exports["default"] = __webpack_exports__["default"];
|
|
72
|
+
exports.hasEnabledTelemetryExporters = __webpack_exports__.hasEnabledTelemetryExporters;
|
|
73
|
+
exports.loadServerPlugins = __webpack_exports__.loadServerPlugins;
|
|
74
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
75
|
+
"TelemetryCanaryOrchestrator",
|
|
76
|
+
"TelemetryRegistry",
|
|
77
|
+
"TelemetryStartupHealthError",
|
|
78
|
+
"applyPlugins",
|
|
79
|
+
"createOtlpTelemetryExporter",
|
|
80
|
+
"createProdServer",
|
|
81
|
+
"createTelemetryAwareMetrics",
|
|
82
|
+
"createVictoriaMetricsTelemetryExporter",
|
|
83
|
+
"default",
|
|
84
|
+
"hasEnabledTelemetryExporters",
|
|
85
|
+
"loadServerPlugins"
|
|
86
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
87
|
+
Object.defineProperty(exports, '__esModule', {
|
|
88
|
+
value: true
|
|
89
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
ContractGateAutopilot: ()=>server_core_namespaceObject.ContractGateAutopilot
|
|
28
|
+
});
|
|
29
|
+
const server_core_namespaceObject = require("@modern-js/server-core");
|
|
30
|
+
exports.ContractGateAutopilot = __webpack_exports__.ContractGateAutopilot;
|
|
31
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
32
|
+
"ContractGateAutopilot"
|
|
33
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
34
|
+
Object.defineProperty(exports, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
getServerConfigPath: ()=>getServerConfigPath,
|
|
37
|
+
loadConfig: ()=>loadConfig,
|
|
38
|
+
requireConfig: ()=>requireConfig
|
|
39
|
+
});
|
|
40
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
41
|
+
const external_flatted_namespaceObject = require("flatted");
|
|
42
|
+
const external_path_namespaceObject = require("path");
|
|
43
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
44
|
+
const getServerConfigPath = (distDirectory, serverConfigFile)=>{
|
|
45
|
+
const fileName = serverConfigFile || 'server.js';
|
|
46
|
+
return external_path_default().join(distDirectory, fileName);
|
|
47
|
+
};
|
|
48
|
+
const requireConfig = (serverConfigPath)=>{
|
|
49
|
+
if (utils_namespaceObject.fs.pathExistsSync(serverConfigPath)) return (0, utils_namespaceObject.compatibleRequire)(serverConfigPath) || {};
|
|
50
|
+
return {};
|
|
51
|
+
};
|
|
52
|
+
const loadConfig = ({ cliConfig, serverConfig, resolvedConfigPath })=>{
|
|
53
|
+
let outputConfig = {};
|
|
54
|
+
if (utils_namespaceObject.fs.pathExistsSync(resolvedConfigPath)) try {
|
|
55
|
+
const content = utils_namespaceObject.fs.readFileSync(resolvedConfigPath, 'utf8');
|
|
56
|
+
outputConfig = (0, external_flatted_namespaceObject.parse)(content) || {};
|
|
57
|
+
} catch (_error) {
|
|
58
|
+
outputConfig = {};
|
|
59
|
+
}
|
|
60
|
+
return utils_namespaceObject.lodash.merge({}, outputConfig, serverConfig || {}, cliConfig || {});
|
|
61
|
+
};
|
|
62
|
+
exports.getServerConfigPath = __webpack_exports__.getServerConfigPath;
|
|
63
|
+
exports.loadConfig = __webpack_exports__.loadConfig;
|
|
64
|
+
exports.requireConfig = __webpack_exports__.requireConfig;
|
|
65
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
66
|
+
"getServerConfigPath",
|
|
67
|
+
"loadConfig",
|
|
68
|
+
"requireConfig"
|
|
69
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
70
|
+
Object.defineProperty(exports, '__esModule', {
|
|
71
|
+
value: true
|
|
72
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
metrics: ()=>metrics
|
|
28
|
+
});
|
|
29
|
+
const noop = ()=>{};
|
|
30
|
+
const metrics = {
|
|
31
|
+
emitCounter: noop,
|
|
32
|
+
emitTimer: noop,
|
|
33
|
+
gauges: noop
|
|
34
|
+
};
|
|
35
|
+
exports.metrics = __webpack_exports__.metrics;
|
|
36
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
37
|
+
"metrics"
|
|
38
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
39
|
+
Object.defineProperty(exports, '__esModule', {
|
|
40
|
+
value: true
|
|
41
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
createRenderHandler: ()=>createRenderHandler
|
|
37
|
+
});
|
|
38
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
39
|
+
const external_path_namespaceObject = require("path");
|
|
40
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
41
|
+
const external_constants_namespaceObject = require("../../constants");
|
|
42
|
+
const shouldFlushServerHeader_namespaceObject = require("../preload/shouldFlushServerHeader");
|
|
43
|
+
const external_reader_namespaceObject = require("./reader");
|
|
44
|
+
const external_ssr_js_namespaceObject = require("./ssr.js");
|
|
45
|
+
const external_static_namespaceObject = require("./static");
|
|
46
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
47
|
+
const calcFallback = (metaName)=>`x-${(0, utils_namespaceObject.cutNameByHyphen)(metaName)}-ssr-fallback`;
|
|
48
|
+
const readUnsafeHeaders = (ssrConfig)=>{
|
|
49
|
+
if (!ssrConfig || 'object' != typeof ssrConfig) return;
|
|
50
|
+
const unsafeHeaders = ssrConfig.unsafeHeaders;
|
|
51
|
+
if (!Array.isArray(unsafeHeaders)) return;
|
|
52
|
+
return unsafeHeaders.filter((header)=>'string' == typeof header && header.trim().length > 0);
|
|
53
|
+
};
|
|
54
|
+
const resolveUnsafeHeaders = (conf, entryName)=>{
|
|
55
|
+
if (!entryName) return readUnsafeHeaders(conf.server?.ssr);
|
|
56
|
+
const entrySSRConfig = conf.server?.ssrByEntries?.[entryName];
|
|
57
|
+
return readUnsafeHeaders(entrySSRConfig) ?? readUnsafeHeaders(conf.server?.ssr);
|
|
58
|
+
};
|
|
59
|
+
const createRenderHandler = ({ distDir, staticGenerate, conf, forceCSR, nonce, ssrRender, metaName = 'modern-js' })=>async function({ ctx, route, runner }) {
|
|
60
|
+
if (ctx.resHasHandled()) return null;
|
|
61
|
+
const { entryPath, urlPath } = route;
|
|
62
|
+
const unsafeHeaders = resolveUnsafeHeaders(conf, route.entryName);
|
|
63
|
+
const entry = external_path_default().join(distDir, entryPath);
|
|
64
|
+
if (!route.isSPA) {
|
|
65
|
+
const result = await (0, external_static_namespaceObject.handleDirectory)(ctx, entry, urlPath);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
const templatePath = entry;
|
|
69
|
+
const content = await (0, external_reader_namespaceObject.readFile)(templatePath);
|
|
70
|
+
if (!content) return null;
|
|
71
|
+
const useCSR = forceCSR && (ctx.query.csr || ctx.headers[calcFallback(metaName)]);
|
|
72
|
+
if (route.isSSR && !useCSR) try {
|
|
73
|
+
const userAgent = ctx.getReqHeader('User-Agent');
|
|
74
|
+
const disablePreload = Boolean(ctx.headers[`x-${(0, utils_namespaceObject.cutNameByHyphen)(metaName)}-disable-preload`]);
|
|
75
|
+
if ((0, shouldFlushServerHeader_namespaceObject.shouldFlushServerHeader)(conf.server, userAgent, disablePreload)) {
|
|
76
|
+
const { flushServerHeader } = await import("../preload");
|
|
77
|
+
flushServerHeader({
|
|
78
|
+
serverConf: conf.server,
|
|
79
|
+
ctx,
|
|
80
|
+
distDir,
|
|
81
|
+
template: content.toString(),
|
|
82
|
+
headers: {
|
|
83
|
+
'Content-Type': utils_namespaceObject.mime.contentType(external_path_default().extname(templatePath))
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const ssrRenderOptions = {
|
|
88
|
+
distDir,
|
|
89
|
+
entryName: route.entryName,
|
|
90
|
+
urlPath: route.urlPath,
|
|
91
|
+
bundle: route.bundle,
|
|
92
|
+
template: content.toString(),
|
|
93
|
+
staticGenerate,
|
|
94
|
+
unsafeHeaders,
|
|
95
|
+
nonce
|
|
96
|
+
};
|
|
97
|
+
const result = await (ssrRender ? ssrRender(ctx, ssrRenderOptions, runner) : external_ssr_js_namespaceObject.render(ctx, {
|
|
98
|
+
distDir,
|
|
99
|
+
entryName: route.entryName,
|
|
100
|
+
urlPath: route.urlPath,
|
|
101
|
+
bundle: route.bundle,
|
|
102
|
+
template: content.toString(),
|
|
103
|
+
staticGenerate,
|
|
104
|
+
unsafeHeaders,
|
|
105
|
+
nonce
|
|
106
|
+
}, runner));
|
|
107
|
+
return result;
|
|
108
|
+
} catch (err) {
|
|
109
|
+
ctx.error(external_constants_namespaceObject.ERROR_DIGEST.ERENDER, err.stack || err.message);
|
|
110
|
+
ctx.res.set(calcFallback(metaName), '1');
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
content: route.entryName ? (0, external_utils_js_namespaceObject.injectServerData)(content.toString(), ctx, {
|
|
114
|
+
unsafeHeaders
|
|
115
|
+
}) : content,
|
|
116
|
+
contentType: utils_namespaceObject.mime.contentType(external_path_default().extname(templatePath))
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
exports.createRenderHandler = __webpack_exports__.createRenderHandler;
|
|
120
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
121
|
+
"createRenderHandler"
|
|
122
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
123
|
+
Object.defineProperty(exports, '__esModule', {
|
|
124
|
+
value: true
|
|
125
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
render: ()=>render
|
|
37
|
+
});
|
|
38
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
39
|
+
const external_path_namespaceObject = require("path");
|
|
40
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
41
|
+
const external_cache_namespaceObject = require("./cache");
|
|
42
|
+
var external_cache_default = /*#__PURE__*/ __webpack_require__.n(external_cache_namespaceObject);
|
|
43
|
+
const external_measure_namespaceObject = require("./measure");
|
|
44
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
45
|
+
const render = async (ctx, renderOptions, runner)=>{
|
|
46
|
+
const { urlPath, bundle, distDir, template, entryName, staticGenerate, enableUnsafeCtx = false, unsafeHeaders, nonce } = renderOptions;
|
|
47
|
+
const bundleJS = external_path_default().join(distDir, bundle);
|
|
48
|
+
const loadableUri = external_path_default().join(distDir, utils_namespaceObject.LOADABLE_STATS_FILE);
|
|
49
|
+
const loadableStats = utils_namespaceObject.fs.existsSync(loadableUri) ? require(loadableUri) : '';
|
|
50
|
+
const routesManifestUri = external_path_default().join(distDir, utils_namespaceObject.ROUTE_MANIFEST_FILE);
|
|
51
|
+
const routeManifest = utils_namespaceObject.fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
52
|
+
const context = {
|
|
53
|
+
request: {
|
|
54
|
+
baseUrl: urlPath,
|
|
55
|
+
params: ctx.params,
|
|
56
|
+
pathname: ctx.path,
|
|
57
|
+
host: ctx.host,
|
|
58
|
+
query: ctx.query,
|
|
59
|
+
url: ctx.href,
|
|
60
|
+
headers: ctx.headers
|
|
61
|
+
},
|
|
62
|
+
response: {
|
|
63
|
+
setHeader: (key, value)=>ctx.res.setHeader(key, value),
|
|
64
|
+
status: (code)=>{
|
|
65
|
+
ctx.res.statusCode = code;
|
|
66
|
+
},
|
|
67
|
+
locals: ctx.res?.locals || {}
|
|
68
|
+
},
|
|
69
|
+
redirection: {},
|
|
70
|
+
template,
|
|
71
|
+
loadableStats,
|
|
72
|
+
routeManifest,
|
|
73
|
+
entryName,
|
|
74
|
+
staticGenerate,
|
|
75
|
+
logger: void 0,
|
|
76
|
+
metrics: void 0,
|
|
77
|
+
reporter: ctx.reporter,
|
|
78
|
+
serverTiming: ctx.serverTiming,
|
|
79
|
+
req: ctx.req,
|
|
80
|
+
res: ctx.res,
|
|
81
|
+
enableUnsafeCtx,
|
|
82
|
+
unsafeHeaders,
|
|
83
|
+
nonce
|
|
84
|
+
};
|
|
85
|
+
context.logger = (0, external_measure_namespaceObject.createLogger)(context, ctx.logger);
|
|
86
|
+
context.metrics = (0, external_measure_namespaceObject.createMetrics)(context, ctx.metrics);
|
|
87
|
+
runner.extendSSRContext(context);
|
|
88
|
+
const bundleJSContent = await Promise.resolve(require(bundleJS));
|
|
89
|
+
const serverRender = bundleJSContent[utils_namespaceObject.SERVER_RENDER_FUNCTION_NAME];
|
|
90
|
+
const content = await external_cache_default()(serverRender, ctx)(context);
|
|
91
|
+
const { url, status = 302 } = context.redirection;
|
|
92
|
+
if (url) return {
|
|
93
|
+
content: url,
|
|
94
|
+
contentType: '',
|
|
95
|
+
statusCode: status,
|
|
96
|
+
redirect: true
|
|
97
|
+
};
|
|
98
|
+
if ('string' == typeof content) return {
|
|
99
|
+
content: (0, external_utils_js_namespaceObject.injectServerData)(content, ctx, {
|
|
100
|
+
unsafeHeaders
|
|
101
|
+
}),
|
|
102
|
+
contentType: utils_namespaceObject.mime.contentType('html')
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
content: '',
|
|
106
|
+
contentStream: (0, external_utils_js_namespaceObject.injectServerDataStream)(content, ctx, {
|
|
107
|
+
unsafeHeaders
|
|
108
|
+
}),
|
|
109
|
+
contentType: utils_namespaceObject.mime.contentType('html')
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
exports.render = __webpack_exports__.render;
|
|
113
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
114
|
+
"render"
|
|
115
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
116
|
+
Object.defineProperty(exports, '__esModule', {
|
|
117
|
+
value: true
|
|
118
|
+
});
|