@modern-js/app-tools 2.49.3-alpha.1 → 2.49.3-alpha.11
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/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/plugins/deploy/index.js +60 -25
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +36 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +66 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +55 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/plugins/deploy/index.js +124 -74
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +99 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +56 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +197 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/plugins/deploy/index.js +60 -25
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +35 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +32 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +63 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +1 -0
- package/dist/types/plugins/deploy/{entrys → platforms}/vercel.d.ts +2 -3
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +8 -8
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -97
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -43
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -73
- /package/dist/cjs/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/cjs/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/esm/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/esm/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/esm-node/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/esm-node/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/types/plugins/deploy/{entrys → platforms}/netlify.d.ts +0 -0
- /package/dist/types/plugins/deploy/{entrys → platforms}/node.d.ts +0 -0
|
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(getServerRoutes_exports);
|
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_fs = __toESM(require("fs"));
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
|
+
var import_routes = require("../utils/routes");
|
|
37
38
|
var import_utils2 = require("./utils");
|
|
38
39
|
const applyBaseUrl = (baseUrl, routes) => {
|
|
39
40
|
if (baseUrl) {
|
|
@@ -106,14 +107,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
106
107
|
const { packageName } = appContext;
|
|
107
108
|
const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
|
108
109
|
let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
|
|
109
|
-
const
|
|
110
|
-
const entryOptions = (0, import_utils.getEntryOptions)(entryName,
|
|
110
|
+
const isMain = (0, import_routes.isMainEntry)(entryName, mainEntryName);
|
|
111
|
+
const entryOptions = (0, import_utils.getEntryOptions)(entryName, isMain, ssr, ssrByEntries, packageName);
|
|
111
112
|
const isSSR = Boolean(entryOptions);
|
|
112
113
|
const isWorker = Boolean(workerSSR);
|
|
113
114
|
const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
|
|
114
115
|
const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
|
|
115
116
|
let route = {
|
|
116
|
-
urlPath: `/${
|
|
117
|
+
urlPath: `/${isMain ? "" : entryName}`,
|
|
117
118
|
entryName,
|
|
118
119
|
entryPath: (0, import_utils.removeLeadingSlash)(import_path.default.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
|
|
119
120
|
isSPA: true,
|
|
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(deploy_exports);
|
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
36
|
var import_std_env = require("std-env");
|
|
37
|
+
var import_routes = require("../../utils/routes");
|
|
37
38
|
var import_utils2 = require("./utils");
|
|
38
39
|
var import_dependencies = require("./dependencies");
|
|
39
40
|
var deploy_default = () => ({
|
|
@@ -47,10 +48,11 @@ var deploy_default = () => ({
|
|
|
47
48
|
return {
|
|
48
49
|
async beforeDeploy() {
|
|
49
50
|
const appContext = api.useAppContext();
|
|
51
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
52
|
+
const { source: { mainEntryName } } = modernConfig;
|
|
50
53
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
|
51
54
|
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
|
52
55
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
53
|
-
const configContext = api.useResolvedConfigContext();
|
|
54
56
|
let outputDirectory = import_path.default.join(appDirectory, ".output");
|
|
55
57
|
let funcsDirectory = outputDirectory;
|
|
56
58
|
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
|
@@ -58,11 +60,48 @@ var deploy_default = () => ({
|
|
|
58
60
|
await import_utils.fs.remove(outputDirectory);
|
|
59
61
|
await import_utils.fs.copy(distDirectory, outputDirectory);
|
|
60
62
|
}
|
|
63
|
+
if (deployTarget === "netlify") {
|
|
64
|
+
const netlifyOutput = import_path.default.join(appDirectory, ".netlify");
|
|
65
|
+
funcsDirectory = import_path.default.join(netlifyOutput, "functions");
|
|
66
|
+
const routes = [];
|
|
67
|
+
if (!needModernServer) {
|
|
68
|
+
entrypoints.forEach((entry) => {
|
|
69
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
|
70
|
+
routes.push({
|
|
71
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
|
72
|
+
dest: `/html/${entry.entryName}/index.html`,
|
|
73
|
+
status: 200
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
routes.push({
|
|
78
|
+
src: `/*`,
|
|
79
|
+
dest: `/.netlify/functions/index`,
|
|
80
|
+
status: 200
|
|
81
|
+
});
|
|
82
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
|
|
83
|
+
}
|
|
84
|
+
console.log("routes", routes, needModernServer);
|
|
85
|
+
const redirectContent = routes.map((route) => {
|
|
86
|
+
return `${route.src} ${route.dest} ${route.status}`;
|
|
87
|
+
}).join("\n");
|
|
88
|
+
console.log("redirectContent", redirectContent);
|
|
89
|
+
await import_utils.fs.remove(outputDirectory);
|
|
90
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
|
91
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
|
92
|
+
filter: (src) => {
|
|
93
|
+
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
|
94
|
+
return !src.includes(distStaticDirectory);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
|
|
98
|
+
await import_utils.fs.writeFile(redirectFilePath, redirectContent);
|
|
99
|
+
}
|
|
61
100
|
if (deployTarget === "vercel") {
|
|
62
101
|
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
|
63
102
|
await import_utils.fs.remove(vercelOutput);
|
|
64
103
|
outputDirectory = import_path.default.join(vercelOutput, "output");
|
|
65
|
-
const
|
|
104
|
+
const config = {
|
|
66
105
|
version: 3,
|
|
67
106
|
routes: [
|
|
68
107
|
{
|
|
@@ -79,8 +118,9 @@ var deploy_default = () => ({
|
|
|
79
118
|
};
|
|
80
119
|
if (!needModernServer) {
|
|
81
120
|
entrypoints.forEach((entry) => {
|
|
82
|
-
|
|
83
|
-
|
|
121
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
|
122
|
+
config.routes.push({
|
|
123
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
|
84
124
|
headers: {
|
|
85
125
|
"cache-control": "s-maxage=0"
|
|
86
126
|
},
|
|
@@ -88,13 +128,13 @@ var deploy_default = () => ({
|
|
|
88
128
|
});
|
|
89
129
|
});
|
|
90
130
|
} else {
|
|
91
|
-
|
|
131
|
+
config.routes.push({
|
|
92
132
|
src: "/(.*)",
|
|
93
133
|
dest: `/index`
|
|
94
134
|
});
|
|
95
135
|
}
|
|
96
136
|
await import_utils.fs.ensureDir(outputDirectory);
|
|
97
|
-
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"),
|
|
137
|
+
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config, {
|
|
98
138
|
spaces: 2
|
|
99
139
|
});
|
|
100
140
|
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
|
@@ -112,10 +152,6 @@ var deploy_default = () => ({
|
|
|
112
152
|
return !src.includes(distStaticDirectory);
|
|
113
153
|
}
|
|
114
154
|
});
|
|
115
|
-
const apiDirectory2 = import_path.default.join(funcsDirectory, "api");
|
|
116
|
-
if (await import_utils.fs.pathExists(apiDirectory2)) {
|
|
117
|
-
await import_utils.fs.rename(apiDirectory2, import_path.default.join(funcsDirectory, "_api"));
|
|
118
|
-
}
|
|
119
155
|
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
|
120
156
|
runtime: "nodejs16.x",
|
|
121
157
|
handler: "index.js",
|
|
@@ -125,13 +161,6 @@ var deploy_default = () => ({
|
|
|
125
161
|
});
|
|
126
162
|
}
|
|
127
163
|
}
|
|
128
|
-
const { bff } = configContext;
|
|
129
|
-
const config = {
|
|
130
|
-
output: {
|
|
131
|
-
path: "."
|
|
132
|
-
},
|
|
133
|
-
bff
|
|
134
|
-
};
|
|
135
164
|
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
|
136
165
|
const serverAppContext = {
|
|
137
166
|
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
|
@@ -143,28 +172,34 @@ var deploy_default = () => ({
|
|
|
143
172
|
console.log("deployTarget111111111", deployTarget);
|
|
144
173
|
switch (deployTarget) {
|
|
145
174
|
case "node": {
|
|
146
|
-
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./
|
|
175
|
+
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
|
|
147
176
|
code = genNodeEntry({
|
|
148
177
|
plugins,
|
|
149
|
-
config,
|
|
178
|
+
config: modernConfig,
|
|
150
179
|
appContext: serverAppContext
|
|
151
180
|
});
|
|
152
181
|
break;
|
|
153
182
|
}
|
|
154
183
|
case "vercel": {
|
|
155
|
-
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./
|
|
156
|
-
|
|
184
|
+
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
|
|
185
|
+
const serverAppContext2 = {
|
|
186
|
+
sharedDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, sharedDirectory)),
|
|
187
|
+
apiDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, apiDirectory)),
|
|
188
|
+
lambdaDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, lambdaDirectory)),
|
|
189
|
+
metaName
|
|
190
|
+
};
|
|
191
|
+
code = await genVercelEntry({
|
|
157
192
|
plugins,
|
|
158
|
-
config,
|
|
159
|
-
appContext:
|
|
193
|
+
config: modernConfig,
|
|
194
|
+
appContext: serverAppContext2
|
|
160
195
|
});
|
|
161
196
|
break;
|
|
162
197
|
}
|
|
163
198
|
case "netlify": {
|
|
164
|
-
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./
|
|
199
|
+
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
|
|
165
200
|
code = genNetlifyEntry({
|
|
166
201
|
plugins,
|
|
167
|
-
config,
|
|
202
|
+
config: modernConfig,
|
|
168
203
|
appContext: serverAppContext
|
|
169
204
|
});
|
|
170
205
|
break;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("node:fs/promises");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const { createProdServer } = require("@modern-js/prod-server");
|
|
5
|
+
p_genPluginImportsCode;
|
|
6
|
+
if (!process.env.NODE_ENV) {
|
|
7
|
+
process.env.NODE_ENV = "production";
|
|
8
|
+
}
|
|
9
|
+
async function loadRoutes(routeFilepath) {
|
|
10
|
+
try {
|
|
11
|
+
await fs.access(routeFilepath);
|
|
12
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
13
|
+
const routeSpec = JSON.parse(content);
|
|
14
|
+
return routeSpec.routes || [];
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function main() {
|
|
21
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
22
|
+
const routes = await loadRoutes(routeFilepath);
|
|
23
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
24
|
+
const prodServerOptions = {
|
|
25
|
+
pwd: __dirname,
|
|
26
|
+
routes,
|
|
27
|
+
disableCustomHook: true,
|
|
28
|
+
...dynamicProdOptions
|
|
29
|
+
};
|
|
30
|
+
const app = await createProdServer(prodServerOptions);
|
|
31
|
+
const port = process.env.PORT || 8080;
|
|
32
|
+
app.listen(port, () => {
|
|
33
|
+
console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
main();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var platform_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(platform_exports);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vercel_exports = {};
|
|
30
|
+
__export(vercel_exports, {
|
|
31
|
+
genVercelEntry: () => genVercelEntry
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vercel_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_utils2 = require("../utils");
|
|
37
|
+
async function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
38
|
+
const defaultConfig = {
|
|
39
|
+
output: {
|
|
40
|
+
path: "."
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
console.log("appContext.sharedDirectory", appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory);
|
|
44
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
45
|
+
const dynamicProdOptions = {
|
|
46
|
+
config: config || defaultConfig,
|
|
47
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
|
48
|
+
plugins,
|
|
49
|
+
appContext: appContext ? {
|
|
50
|
+
sharedDirectory: appContext.sharedDirectory,
|
|
51
|
+
apiDirectory: appContext.apiDirectory,
|
|
52
|
+
lambdaDirectory: appContext.lambdaDirectory
|
|
53
|
+
} : "undefined"
|
|
54
|
+
};
|
|
55
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
|
56
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace(
|
|
57
|
+
"p_dynamicProdOptions",
|
|
58
|
+
// JSON.stringify(dynamicProdOptions),
|
|
59
|
+
JSON.stringify(dynamicProdOptions)
|
|
60
|
+
);
|
|
61
|
+
return entryCode;
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
genVercelEntry
|
|
66
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("node:fs/promises");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const { createProdServer } = require("@modern-js/prod-server");
|
|
5
|
+
p_genPluginImportsCode;
|
|
6
|
+
if (!process.env.NODE_ENV) {
|
|
7
|
+
process.env.NODE_ENV = "production";
|
|
8
|
+
}
|
|
9
|
+
let requestHandler = null;
|
|
10
|
+
let handlerCreationPromise = null;
|
|
11
|
+
async function loadRoutes(routeFilepath) {
|
|
12
|
+
try {
|
|
13
|
+
await fs.access(routeFilepath);
|
|
14
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
15
|
+
const routeSpec = JSON.parse(content);
|
|
16
|
+
return routeSpec.routes || [];
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function initServer() {
|
|
23
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
24
|
+
const routes = await loadRoutes(routeFilepath);
|
|
25
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
26
|
+
const prodServerOptions = {
|
|
27
|
+
pwd: __dirname,
|
|
28
|
+
routes,
|
|
29
|
+
disableCustomHook: true,
|
|
30
|
+
...dynamicProdOptions
|
|
31
|
+
};
|
|
32
|
+
const app = await createProdServer(prodServerOptions);
|
|
33
|
+
return app.getRequestListener();
|
|
34
|
+
}
|
|
35
|
+
async function createHandler() {
|
|
36
|
+
if (!handlerCreationPromise) {
|
|
37
|
+
handlerCreationPromise = (async () => {
|
|
38
|
+
try {
|
|
39
|
+
requestHandler = await initServer();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("Error creating server:", error);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
}
|
|
46
|
+
await handlerCreationPromise;
|
|
47
|
+
return requestHandler;
|
|
48
|
+
}
|
|
49
|
+
createHandler();
|
|
50
|
+
module.exports = async (req, res) => {
|
|
51
|
+
if (!requestHandler) {
|
|
52
|
+
await createHandler();
|
|
53
|
+
}
|
|
54
|
+
return requestHandler(req, res);
|
|
55
|
+
};
|
package/dist/cjs/utils/routes.js
CHANGED
|
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var routes_exports = {};
|
|
30
30
|
__export(routes_exports, {
|
|
31
31
|
generateRoutes: () => generateRoutes,
|
|
32
|
-
getPathWithoutExt: () => getPathWithoutExt
|
|
32
|
+
getPathWithoutExt: () => getPathWithoutExt,
|
|
33
|
+
isMainEntry: () => isMainEntry
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(routes_exports);
|
|
35
36
|
var import_path = __toESM(require("path"));
|
|
@@ -45,8 +46,12 @@ const getPathWithoutExt = (filename) => {
|
|
|
45
46
|
const extname = import_path.default.extname(filename);
|
|
46
47
|
return filename.slice(0, -extname.length);
|
|
47
48
|
};
|
|
49
|
+
const isMainEntry = (entryName, mainEntryName) => {
|
|
50
|
+
return entryName === (mainEntryName || import_utils.MAIN_ENTRY_NAME);
|
|
51
|
+
};
|
|
48
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
53
|
0 && (module.exports = {
|
|
50
54
|
generateRoutes,
|
|
51
|
-
getPathWithoutExt
|
|
55
|
+
getPathWithoutExt,
|
|
56
|
+
isMainEntry
|
|
52
57
|
});
|
|
@@ -4,7 +4,8 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
|
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import fs from "fs";
|
|
7
|
-
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY,
|
|
7
|
+
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
8
|
+
import { isMainEntry } from "../utils/routes";
|
|
8
9
|
import { walkDirectory } from "./utils";
|
|
9
10
|
var applyBaseUrl = function(baseUrl, routes) {
|
|
10
11
|
if (baseUrl) {
|
|
@@ -75,14 +76,14 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
|
75
76
|
var workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
|
76
77
|
var htmlRoutes = entrypoints.reduce(function(previous, param) {
|
|
77
78
|
var entryName = param.entryName;
|
|
78
|
-
var
|
|
79
|
-
var entryOptions = getEntryOptions(entryName,
|
|
79
|
+
var isMain = isMainEntry(entryName, mainEntryName);
|
|
80
|
+
var entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
|
|
80
81
|
var isSSR = Boolean(entryOptions);
|
|
81
82
|
var isWorker = Boolean(workerSSR);
|
|
82
83
|
var isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
|
|
83
84
|
var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
|
|
84
85
|
var route = {
|
|
85
|
-
urlPath: "/".concat(
|
|
86
|
+
urlPath: "/".concat(isMain ? "" : entryName),
|
|
86
87
|
entryName,
|
|
87
88
|
entryPath: removeLeadingSlash(path.posix.normalize("".concat(htmlPath, "/").concat(entryName).concat(disableHtmlFolder ? ".html" : "/index.html"))),
|
|
88
89
|
isSPA: true,
|