@next-core/brick-container 2.77.38 → 2.78.1
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/dll-of-editor-bricks-helper.779e06a3.js +8 -0
- package/dist/dll-of-editor-bricks-helper.779e06a3.js.map +1 -0
- package/dist/{dll.3c993221.js → dll.4dbe639b.js} +2 -2
- package/dist/{dll.3c993221.js.map → dll.4dbe639b.js.map} +1 -1
- package/dist/index.html +1 -1
- package/dist/{main.58553f7a2dbb3c2086fb.js → main.82bc0836495c15fbcbe1.js} +2 -2
- package/dist/{main.58553f7a2dbb3c2086fb.js.map → main.82bc0836495c15fbcbe1.js.map} +1 -1
- package/package.json +6 -6
- package/serve/getEnv.js +23 -6
- package/serve/getIndexHtml.js +92 -0
- package/serve/getProxies.js +128 -30
- package/serve/serve.js +12 -89
- package/serve/serveLocal.js +69 -18
- package/serve/utils.js +61 -37
- package/dist/dll-of-editor-bricks-helper.e92a5aee.js +0 -8
- package/dist/dll-of-editor-bricks-helper.e92a5aee.js.map +0 -1
package/serve/getProxies.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
tryFiles,
|
|
16
16
|
removeCacheHeaders,
|
|
17
17
|
} = require("./utils");
|
|
18
|
+
const { getIndexHtml } = require("./getIndexHtml");
|
|
18
19
|
|
|
19
20
|
module.exports = (env) => {
|
|
20
21
|
const {
|
|
@@ -35,9 +36,10 @@ module.exports = (env) => {
|
|
|
35
36
|
brickPackagesDir,
|
|
36
37
|
alternativeBrickPackagesDir,
|
|
37
38
|
useLegacyBootstrap,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
legacyStandaloneAppsConfig,
|
|
40
|
+
legacyAllAppsConfig,
|
|
41
|
+
saStaticRoot,
|
|
42
|
+
useLocalContainer,
|
|
41
43
|
} = env;
|
|
42
44
|
|
|
43
45
|
const pathRewriteFactory = (seg) =>
|
|
@@ -56,25 +58,24 @@ module.exports = (env) => {
|
|
|
56
58
|
},
|
|
57
59
|
};
|
|
58
60
|
if (useRemote) {
|
|
59
|
-
for (const standaloneConfig of
|
|
60
|
-
const assetRoot = standaloneConfig
|
|
61
|
-
? standaloneConfig.standaloneVersion === 2
|
|
62
|
-
? standaloneConfig.publicPrefix
|
|
63
|
-
: `${standaloneConfig.appRoot}-/`
|
|
64
|
-
: "";
|
|
61
|
+
for (const standaloneConfig of legacyAllAppsConfig) {
|
|
62
|
+
const assetRoot = standaloneConfig ? `${standaloneConfig.appRoot}-/` : "";
|
|
65
63
|
if (standaloneConfig) {
|
|
66
64
|
// 在「独立应用」模式中,静态资源路径在 `your-app/-/` 目录下。
|
|
67
65
|
proxyPaths.push(assetRoot);
|
|
68
66
|
proxyPaths.push(`${standaloneConfig.appRoot}conf.yaml`);
|
|
69
|
-
if (standaloneConfig.standaloneVersion === 2) {
|
|
70
|
-
proxyPaths.push(`${standaloneConfig.appRoot}-/`);
|
|
71
|
-
}
|
|
72
67
|
} else {
|
|
73
68
|
const assetPaths = ["bricks", "micro-apps", "templates"];
|
|
74
69
|
proxyPaths.push(...assetPaths.map((p) => `${assetRoot}${p}`));
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
|
|
73
|
+
proxyPaths.push(
|
|
74
|
+
`${saStaticRoot}-/`,
|
|
75
|
+
`${saStaticRoot}:appId/versions/:appVersion/conf.yaml`,
|
|
76
|
+
`${saStaticRoot}:appId/versions/:appVersion/webroot/-/`
|
|
77
|
+
);
|
|
78
|
+
|
|
78
79
|
apiProxyOptions.onProxyRes = (proxyRes, req, res) => {
|
|
79
80
|
if (env.asCdn) {
|
|
80
81
|
return;
|
|
@@ -84,23 +85,33 @@ module.exports = (env) => {
|
|
|
84
85
|
let reqIsBootstrap =
|
|
85
86
|
req.path === "/next/api/auth/bootstrap" ||
|
|
86
87
|
req.path === "/next/api/auth/v2/bootstrap";
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
let isStandalone = false;
|
|
89
|
+
let publicRootWithVersion = false;
|
|
90
|
+
if (!reqIsBootstrap) {
|
|
91
|
+
const regex =
|
|
92
|
+
/^(?:\/next)?\/sa-static\/[^/]+\/versions\/[^/]+\/webroot\/-\/bootstrap\.[^.]+\.json$/;
|
|
93
|
+
if (regex.test(req.path)) {
|
|
94
|
+
reqIsBootstrap = true;
|
|
95
|
+
isStandalone = true;
|
|
96
|
+
publicRootWithVersion = true;
|
|
97
|
+
}
|
|
98
|
+
if (!reqIsBootstrap) {
|
|
99
|
+
for (const standaloneConfig of legacyStandaloneAppsConfig) {
|
|
100
|
+
const regex = new RegExp(
|
|
101
|
+
`^${escapeRegExp(
|
|
102
|
+
standaloneConfig.appRoot
|
|
103
|
+
)}-/bootstrap\\.[^.]+\\.json$`
|
|
104
|
+
);
|
|
105
|
+
if (regex.test(req.path)) {
|
|
106
|
+
reqIsBootstrap = true;
|
|
107
|
+
isStandalone = true;
|
|
108
|
+
}
|
|
98
109
|
}
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
if (reqIsBootstrap) {
|
|
103
|
-
if (
|
|
114
|
+
if (res.statusCode === 200) {
|
|
104
115
|
// Disable cache for standalone bootstrap for development.
|
|
105
116
|
removeCacheHeaders(proxyRes);
|
|
106
117
|
}
|
|
@@ -109,7 +120,7 @@ module.exports = (env) => {
|
|
|
109
120
|
return raw;
|
|
110
121
|
}
|
|
111
122
|
const result = JSON.parse(raw);
|
|
112
|
-
const data =
|
|
123
|
+
const data = isStandalone ? result : result.data;
|
|
113
124
|
if (localMicroApps.length > 0 || mockedMicroApps.length > 0) {
|
|
114
125
|
data.storyboards = mockedMicroApps
|
|
115
126
|
.map((id) =>
|
|
@@ -156,7 +167,7 @@ module.exports = (env) => {
|
|
|
156
167
|
env,
|
|
157
168
|
id,
|
|
158
169
|
data.brickPackages,
|
|
159
|
-
|
|
170
|
+
publicRootWithVersion
|
|
160
171
|
)
|
|
161
172
|
)
|
|
162
173
|
.filter(Boolean)
|
|
@@ -362,23 +373,106 @@ module.exports = (env) => {
|
|
|
362
373
|
}
|
|
363
374
|
|
|
364
375
|
const rootProxyOptions = {};
|
|
365
|
-
if (
|
|
376
|
+
if (useRemote && !env.asCdn) {
|
|
366
377
|
proxyPaths.push("");
|
|
367
378
|
rootProxyOptions.onProxyRes = (proxyRes, req, res) => {
|
|
368
379
|
if (
|
|
369
380
|
req.method === "GET" &&
|
|
370
381
|
(req.get("accept") || "").includes("text/html")
|
|
371
382
|
) {
|
|
383
|
+
if (res.statusCode === 200) {
|
|
384
|
+
// Disable cache for standalone runtime for development.
|
|
385
|
+
removeCacheHeaders(proxyRes);
|
|
386
|
+
}
|
|
372
387
|
modifyResponse(res, proxyRes, (raw) => {
|
|
373
388
|
if (
|
|
374
389
|
!(
|
|
375
390
|
res.statusCode === 200 &&
|
|
376
|
-
res.get("content-type")
|
|
377
|
-
raw.includes(`/
|
|
391
|
+
(res.get("content-type") || "").includes("text/html") &&
|
|
392
|
+
raw.includes(`/browse-happy.html`)
|
|
378
393
|
)
|
|
379
394
|
) {
|
|
380
395
|
return raw;
|
|
381
396
|
}
|
|
397
|
+
if (useLocalContainer) {
|
|
398
|
+
const pathname = useSubdir
|
|
399
|
+
? req.path.replace(/^\/next\//, "/")
|
|
400
|
+
: req.path;
|
|
401
|
+
const standalone = /\bSTANDALONE_MICRO_APPS\s*=\s*(?:!0|true)/.test(
|
|
402
|
+
raw
|
|
403
|
+
);
|
|
404
|
+
if (standalone) {
|
|
405
|
+
const appDir = pathname
|
|
406
|
+
.split("/")
|
|
407
|
+
.slice(1, pathname.startsWith("/legacy/") ? 3 : 2)
|
|
408
|
+
.concat("")
|
|
409
|
+
.join("/");
|
|
410
|
+
|
|
411
|
+
const appRootMatches = raw.match(/\bAPP_ROOT\s*=\s*("[^"]+")/);
|
|
412
|
+
if (!appRootMatches) {
|
|
413
|
+
const message = "Unexpected: APP_ROOT is not found";
|
|
414
|
+
console.log(message, raw);
|
|
415
|
+
throw new Error(message);
|
|
416
|
+
}
|
|
417
|
+
const appRoot = JSON.parse(appRootMatches[1]);
|
|
418
|
+
|
|
419
|
+
const bootstrapHashMatches = raw.match(
|
|
420
|
+
/\bbootstrap\.([^."]+)\.json\b/
|
|
421
|
+
);
|
|
422
|
+
if (!bootstrapHashMatches) {
|
|
423
|
+
const message = "Unexpected: bootstrapHash is not found";
|
|
424
|
+
console.log(message, raw);
|
|
425
|
+
throw new Error(message);
|
|
426
|
+
}
|
|
427
|
+
const bootstrapHash = bootstrapHashMatches[1];
|
|
428
|
+
|
|
429
|
+
const noAuthGuard = /\bNO_AUTH_GUARD\s*=\s*(?:!0|true)/.test(raw);
|
|
430
|
+
|
|
431
|
+
const publicRootWithVersion =
|
|
432
|
+
/\bPUBLIC_ROOT_WITH_VERSION\s*=\s*(?:!0|true)/.test(raw);
|
|
433
|
+
|
|
434
|
+
if (publicRootWithVersion) {
|
|
435
|
+
const publicPrefixMatches = raw.match(
|
|
436
|
+
/\bvar\s+d\s*=\s*("[^"]+")/
|
|
437
|
+
);
|
|
438
|
+
if (!publicPrefixMatches) {
|
|
439
|
+
const message =
|
|
440
|
+
"Unexpected: PUBLIC_ROOT_WITH_VERSION is true while public-prefix is not found";
|
|
441
|
+
console.log(message, raw);
|
|
442
|
+
throw new Error(message);
|
|
443
|
+
}
|
|
444
|
+
const publicPrefix = JSON.parse(publicPrefixMatches[1]);
|
|
445
|
+
|
|
446
|
+
// const coreVersionMatches = raw.match(/"core\/(?:[^/]+)\/"/);
|
|
447
|
+
// const coreVersion = JSON.parse(coreVersionMatches[0]).split("/")[1];
|
|
448
|
+
const coreVersion = "0.0.0";
|
|
449
|
+
|
|
450
|
+
return getIndexHtml(
|
|
451
|
+
{
|
|
452
|
+
appDir,
|
|
453
|
+
appRoot,
|
|
454
|
+
publicPrefix,
|
|
455
|
+
bootstrapHash,
|
|
456
|
+
coreVersion,
|
|
457
|
+
noAuthGuard,
|
|
458
|
+
standaloneVersion: 2,
|
|
459
|
+
},
|
|
460
|
+
env
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
return getIndexHtml(
|
|
464
|
+
{
|
|
465
|
+
appDir,
|
|
466
|
+
appRoot,
|
|
467
|
+
bootstrapHash,
|
|
468
|
+
noAuthGuard,
|
|
469
|
+
standaloneVersion: 1,
|
|
470
|
+
},
|
|
471
|
+
env
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
return getIndexHtml(null, env);
|
|
475
|
+
}
|
|
382
476
|
const content = useSubdir ? raw : raw.replace(/\/next\//g, "/");
|
|
383
477
|
return env.liveReload
|
|
384
478
|
? appendLiveReloadScript(content, env)
|
|
@@ -426,7 +520,11 @@ module.exports = (env) => {
|
|
|
426
520
|
}
|
|
427
521
|
: {}),
|
|
428
522
|
...proxyPaths.reduce((acc, seg) => {
|
|
429
|
-
acc[
|
|
523
|
+
acc[
|
|
524
|
+
seg.startsWith("/") || seg.startsWith("(/")
|
|
525
|
+
? seg
|
|
526
|
+
: `${baseHref}${seg}`
|
|
527
|
+
] = {
|
|
430
528
|
target: server,
|
|
431
529
|
secure: false,
|
|
432
530
|
changeOrigin: true,
|
package/serve/serve.js
CHANGED
|
@@ -11,101 +11,23 @@ const yaml = require("js-yaml");
|
|
|
11
11
|
const getEnv = require("./getEnv");
|
|
12
12
|
const serveLocal = require("./serveLocal");
|
|
13
13
|
const getProxies = require("./getProxies");
|
|
14
|
-
const { getPatternsToWatch
|
|
14
|
+
const { getPatternsToWatch } = require("./utils");
|
|
15
|
+
const { getIndexHtml, distDir } = require("./getIndexHtml");
|
|
15
16
|
|
|
16
17
|
module.exports = function serve(runtimeFlags) {
|
|
17
18
|
const env = getEnv(runtimeFlags);
|
|
18
19
|
|
|
19
20
|
const app = express();
|
|
20
21
|
|
|
21
|
-
const distDir = path.dirname(
|
|
22
|
-
require.resolve("@next-core/brick-container/dist/index.html")
|
|
23
|
-
);
|
|
24
|
-
|
|
25
22
|
serveLocal(env, app);
|
|
26
23
|
|
|
27
24
|
const serveIndexHtmlFactory = (standaloneConfig) => (_req, res) => {
|
|
28
|
-
|
|
29
|
-
let content = fs.readFileSync(indexHtml, "utf8");
|
|
30
|
-
|
|
31
|
-
if (env.liveReload) {
|
|
32
|
-
content = appendLiveReloadScript(content, env);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Replace nginx ssi placeholders.
|
|
36
|
-
content = content
|
|
37
|
-
.replace(
|
|
38
|
-
new RegExp(
|
|
39
|
-
escapeRegExp("<!--# echo var='base_href' default='/' -->"),
|
|
40
|
-
"g"
|
|
41
|
-
),
|
|
42
|
-
env.baseHref
|
|
43
|
-
)
|
|
44
|
-
.replace(
|
|
45
|
-
new RegExp(
|
|
46
|
-
escapeRegExp("<!--# echo var='core_root' default='' -->"),
|
|
47
|
-
"g"
|
|
48
|
-
),
|
|
49
|
-
`${env.publicCdn ?? ""}${
|
|
50
|
-
standaloneConfig
|
|
51
|
-
? standaloneConfig.standaloneVersion === 2
|
|
52
|
-
? `${standaloneConfig.publicPrefix}core/${standaloneConfig.coreVersion}/`
|
|
53
|
-
: `${standaloneConfig.appRoot}-/core/`
|
|
54
|
-
: ""
|
|
55
|
-
}`
|
|
56
|
-
)
|
|
57
|
-
.replace(
|
|
58
|
-
new RegExp(
|
|
59
|
-
escapeRegExp("<!--# echo var='mock_date' default='' -->"),
|
|
60
|
-
"g"
|
|
61
|
-
),
|
|
62
|
-
env.mockDate ?? ""
|
|
63
|
-
)
|
|
64
|
-
.replace(
|
|
65
|
-
new RegExp(
|
|
66
|
-
escapeRegExp("<!--# echo var='public_cdn' default='' -->"),
|
|
67
|
-
"g"
|
|
68
|
-
),
|
|
69
|
-
env.publicCdn ?? ""
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (standaloneConfig) {
|
|
73
|
-
content = content.replace(
|
|
74
|
-
"</head>",
|
|
75
|
-
[
|
|
76
|
-
"<script>",
|
|
77
|
-
"((w)=>{",
|
|
78
|
-
"w.STANDALONE_MICRO_APPS=!0;",
|
|
79
|
-
`var a=w.APP_ROOT=${JSON.stringify(standaloneConfig.appRoot)};`,
|
|
80
|
-
(standaloneConfig.standaloneVersion === 2
|
|
81
|
-
? [
|
|
82
|
-
"w.PUBLIC_ROOT_WITH_VERSION=!0",
|
|
83
|
-
`var d=${JSON.stringify(standaloneConfig.publicPrefix)}`,
|
|
84
|
-
'var p=w.PUBLIC_ROOT=(w.PUBLIC_CDN||"")+d',
|
|
85
|
-
`w.CORE_ROOT=p+"core/${standaloneConfig.coreVersion}/"`,
|
|
86
|
-
`w.BOOTSTRAP_FILE=a+"-/bootstrap.${standaloneConfig.bootstrapHash}.json"`,
|
|
87
|
-
]
|
|
88
|
-
: [
|
|
89
|
-
'var d=a+"-/"',
|
|
90
|
-
'var p=w.PUBLIC_ROOT=(w.PUBLIC_CDN||"")+d',
|
|
91
|
-
'w.CORE_ROOT=p+"core/"',
|
|
92
|
-
`w.BOOTSTRAP_FILE=d+"bootstrap.${standaloneConfig.bootstrapHash}.json"`,
|
|
93
|
-
]
|
|
94
|
-
)
|
|
95
|
-
.filter(Boolean)
|
|
96
|
-
.join(";"),
|
|
97
|
-
"})(window)",
|
|
98
|
-
"</script></head>",
|
|
99
|
-
].join("")
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
res.send(content);
|
|
25
|
+
res.send(getIndexHtml(standaloneConfig, env));
|
|
104
26
|
};
|
|
105
27
|
|
|
106
28
|
if (!env.useRemote) {
|
|
107
29
|
let fakeAuthHandled = false;
|
|
108
|
-
for (const standaloneConfig of env.
|
|
30
|
+
for (const standaloneConfig of env.legacyStandaloneAppsConfig) {
|
|
109
31
|
// Return a fake `conf.yaml` for standalone micro-apps.
|
|
110
32
|
app.get(`${standaloneConfig.appRoot}conf.yaml`, (req, res) => {
|
|
111
33
|
res.setHeader("content-type", "text/plain");
|
|
@@ -132,7 +54,7 @@ module.exports = function serve(runtimeFlags) {
|
|
|
132
54
|
|
|
133
55
|
if (env.useLocalContainer) {
|
|
134
56
|
const browseHappyHtml = "browse-happy.html";
|
|
135
|
-
for (const standaloneConfig of env.
|
|
57
|
+
for (const standaloneConfig of env.legacyAllAppsConfig) {
|
|
136
58
|
const serveRoot = `${env.baseHref}${
|
|
137
59
|
standaloneConfig ? standaloneConfig.appDir : ""
|
|
138
60
|
}`;
|
|
@@ -145,7 +67,7 @@ module.exports = function serve(runtimeFlags) {
|
|
|
145
67
|
});
|
|
146
68
|
} else {
|
|
147
69
|
// Serve index.html.
|
|
148
|
-
app.get(serveRoot, serveIndexHtmlFactory(standaloneConfig));
|
|
70
|
+
app.get(serveRoot, serveIndexHtmlFactory(standaloneConfig, env));
|
|
149
71
|
|
|
150
72
|
// Serve browse-happy.html.
|
|
151
73
|
app.get(`${env.baseHref}${browseHappyHtml}`, (req, res) => {
|
|
@@ -155,12 +77,13 @@ module.exports = function serve(runtimeFlags) {
|
|
|
155
77
|
|
|
156
78
|
// Serve static files.
|
|
157
79
|
const staticRoot = standaloneConfig
|
|
158
|
-
? standaloneConfig.
|
|
159
|
-
? `${standaloneConfig.publicPrefix}core/${standaloneConfig.coreVersion}/`
|
|
160
|
-
: `${standaloneConfig.appRoot || serveRoot}-/core/`
|
|
80
|
+
? `${standaloneConfig.appRoot || serveRoot}-/core/`
|
|
161
81
|
: serveRoot;
|
|
162
82
|
app.use(staticRoot, express.static(distDir));
|
|
163
83
|
}
|
|
84
|
+
|
|
85
|
+
// Serve static files in next-core for new standalone apps.
|
|
86
|
+
app.use(`${env.saStaticRoot}-/core/:coreVersion/`, express.static(distDir));
|
|
164
87
|
}
|
|
165
88
|
|
|
166
89
|
// Using proxies.
|
|
@@ -221,11 +144,11 @@ module.exports = function serve(runtimeFlags) {
|
|
|
221
144
|
}
|
|
222
145
|
|
|
223
146
|
if (env.useLocalContainer && !env.asCdn) {
|
|
224
|
-
for (const standaloneConfig of env.
|
|
147
|
+
for (const standaloneConfig of env.legacyAllAppsConfig) {
|
|
225
148
|
const serveRoot = `${env.baseHref}${
|
|
226
149
|
standaloneConfig ? standaloneConfig.appDir : ""
|
|
227
150
|
}`;
|
|
228
|
-
app.use(serveRoot, serveIndexHtmlFactory(standaloneConfig));
|
|
151
|
+
app.use(serveRoot, serveIndexHtmlFactory(standaloneConfig, env));
|
|
229
152
|
}
|
|
230
153
|
|
|
231
154
|
// Return a fake 404 page for not-existed apps.
|
package/serve/serveLocal.js
CHANGED
|
@@ -21,24 +21,42 @@ module.exports = (env, app) => {
|
|
|
21
21
|
localMicroApps,
|
|
22
22
|
localTemplates,
|
|
23
23
|
microAppsDir,
|
|
24
|
+
alternativeMicroAppsDir,
|
|
24
25
|
brickPackagesDir,
|
|
25
26
|
alternativeBrickPackagesDir,
|
|
27
|
+
primitiveBrickPackagesDir,
|
|
26
28
|
templatePackagesDir,
|
|
29
|
+
alternativeTemplatePackagesDir,
|
|
27
30
|
mocked,
|
|
28
31
|
mockedMicroAppsDir,
|
|
29
32
|
mockedMicroApps,
|
|
30
|
-
allAppsConfig,
|
|
31
33
|
asCdn,
|
|
34
|
+
legacyStandaloneAppsConfig,
|
|
35
|
+
saStaticRoot,
|
|
32
36
|
} = env;
|
|
33
37
|
let username;
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const serveLocalConfigs = legacyStandaloneAppsConfig
|
|
40
|
+
.map((standaloneConfig) => ({
|
|
41
|
+
publicRoot: `${standaloneConfig.appRoot}-/`,
|
|
42
|
+
isStandalone: true,
|
|
43
|
+
}))
|
|
44
|
+
.concat(
|
|
45
|
+
{
|
|
46
|
+
publicRoot: `${saStaticRoot}-/`,
|
|
47
|
+
isStandalone: true,
|
|
48
|
+
publicRootWithVersion: true,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
publicRoot: baseHref,
|
|
52
|
+
}
|
|
53
|
+
);
|
|
41
54
|
|
|
55
|
+
for (const {
|
|
56
|
+
publicRoot,
|
|
57
|
+
isStandalone,
|
|
58
|
+
publicRootWithVersion,
|
|
59
|
+
} of serveLocalConfigs) {
|
|
42
60
|
// 开发时默认拦截 bootstrap 请求。
|
|
43
61
|
// 如果设定 `REMOTE=true`,则透传远端请求。
|
|
44
62
|
if (useRemote) {
|
|
@@ -62,6 +80,18 @@ module.exports = (env, app) => {
|
|
|
62
80
|
"dist/editors",
|
|
63
81
|
req.params[0]
|
|
64
82
|
),
|
|
83
|
+
path.join(
|
|
84
|
+
primitiveBrickPackagesDir,
|
|
85
|
+
pkgId,
|
|
86
|
+
"dist-editors",
|
|
87
|
+
req.params[0]
|
|
88
|
+
),
|
|
89
|
+
path.join(
|
|
90
|
+
primitiveBrickPackagesDir,
|
|
91
|
+
pkgId,
|
|
92
|
+
"dist/editors",
|
|
93
|
+
req.params[0]
|
|
94
|
+
),
|
|
65
95
|
],
|
|
66
96
|
req,
|
|
67
97
|
res
|
|
@@ -82,6 +112,7 @@ module.exports = (env, app) => {
|
|
|
82
112
|
[
|
|
83
113
|
path.join(brickPackagesDir, pkgId, req.params[0]),
|
|
84
114
|
path.join(alternativeBrickPackagesDir, pkgId, req.params[0]),
|
|
115
|
+
path.join(primitiveBrickPackagesDir, pkgId, req.params[0]),
|
|
85
116
|
],
|
|
86
117
|
req,
|
|
87
118
|
res
|
|
@@ -90,23 +121,35 @@ module.exports = (env, app) => {
|
|
|
90
121
|
);
|
|
91
122
|
});
|
|
92
123
|
|
|
93
|
-
|
|
124
|
+
isStandalone ||
|
|
94
125
|
localMicroApps.forEach((appId) => {
|
|
95
126
|
// 直接返回本地小产品相关文件。
|
|
96
127
|
app.get(`${baseHref}micro-apps/${appId}/*`, (req, res) => {
|
|
97
|
-
|
|
98
|
-
|
|
128
|
+
tryServeFiles(
|
|
129
|
+
[
|
|
130
|
+
path.join(microAppsDir, appId, req.params[0]),
|
|
131
|
+
path.join(alternativeMicroAppsDir, appId, req.params[0]),
|
|
132
|
+
],
|
|
133
|
+
req,
|
|
134
|
+
res
|
|
135
|
+
);
|
|
99
136
|
});
|
|
100
137
|
});
|
|
101
138
|
localTemplates.forEach((pkgId) => {
|
|
102
139
|
// 直接返回本地模板相关文件。
|
|
103
140
|
app.get(`${publicRoot}templates/${pkgId}/*`, (req, res) => {
|
|
104
|
-
|
|
105
|
-
|
|
141
|
+
tryServeFiles(
|
|
142
|
+
[
|
|
143
|
+
path.join(templatePackagesDir, pkgId, req.params[0]),
|
|
144
|
+
path.join(alternativeTemplatePackagesDir, pkgId, req.params[0]),
|
|
145
|
+
],
|
|
146
|
+
req,
|
|
147
|
+
res
|
|
148
|
+
);
|
|
106
149
|
});
|
|
107
150
|
});
|
|
108
151
|
|
|
109
|
-
|
|
152
|
+
isStandalone ||
|
|
110
153
|
mockedMicroApps.forEach((appId) => {
|
|
111
154
|
// 直接返回本地小产品相关文件。
|
|
112
155
|
app.get(`${baseHref}micro-apps/${appId}/*`, (req, res) => {
|
|
@@ -130,7 +173,7 @@ module.exports = (env, app) => {
|
|
|
130
173
|
});
|
|
131
174
|
// API to fulfil the active storyboard.
|
|
132
175
|
asCdn ||
|
|
133
|
-
|
|
176
|
+
isStandalone ||
|
|
134
177
|
localMicroApps.concat(mockedMicroApps).forEach((appId) => {
|
|
135
178
|
app.get(
|
|
136
179
|
`${baseHref}api/auth(/v2)?/bootstrap/${appId}`,
|
|
@@ -147,7 +190,7 @@ module.exports = (env, app) => {
|
|
|
147
190
|
);
|
|
148
191
|
});
|
|
149
192
|
} else {
|
|
150
|
-
if (
|
|
193
|
+
if (isStandalone) {
|
|
151
194
|
app.get(`${publicRoot}bootstrap.hash.json`, (req, res) => {
|
|
152
195
|
res.json({
|
|
153
196
|
navbar: getNavbar(env),
|
|
@@ -161,7 +204,7 @@ module.exports = (env, app) => {
|
|
|
161
204
|
brief: req.query.brief === "true",
|
|
162
205
|
})
|
|
163
206
|
),
|
|
164
|
-
brickPackages: getBrickPackages(env,
|
|
207
|
+
brickPackages: getBrickPackages(env, publicRootWithVersion),
|
|
165
208
|
templatePackages: getTemplatePackages(env),
|
|
166
209
|
});
|
|
167
210
|
});
|
|
@@ -206,6 +249,7 @@ module.exports = (env, app) => {
|
|
|
206
249
|
[
|
|
207
250
|
path.join(brickPackagesDir, req.params[0]),
|
|
208
251
|
path.join(alternativeBrickPackagesDir, req.params[0]),
|
|
252
|
+
path.join(primitiveBrickPackagesDir, req.params[0]),
|
|
209
253
|
],
|
|
210
254
|
req,
|
|
211
255
|
res
|
|
@@ -218,6 +262,7 @@ module.exports = (env, app) => {
|
|
|
218
262
|
[
|
|
219
263
|
...(mocked ? [path.join(mockedMicroAppsDir, req.params[0])] : []),
|
|
220
264
|
path.join(microAppsDir, req.params[0]),
|
|
265
|
+
path.join(alternativeMicroAppsDir, req.params[0]),
|
|
221
266
|
],
|
|
222
267
|
req,
|
|
223
268
|
res
|
|
@@ -226,8 +271,14 @@ module.exports = (env, app) => {
|
|
|
226
271
|
|
|
227
272
|
// 直接返回模板库 js 文件。
|
|
228
273
|
app.get(`${publicRoot}templates/*`, (req, res) => {
|
|
229
|
-
|
|
230
|
-
|
|
274
|
+
tryServeFiles(
|
|
275
|
+
[
|
|
276
|
+
path.join(templatePackagesDir, req.params[0]),
|
|
277
|
+
path.join(alternativeTemplatePackagesDir, req.params[0]),
|
|
278
|
+
],
|
|
279
|
+
req,
|
|
280
|
+
res
|
|
281
|
+
);
|
|
231
282
|
});
|
|
232
283
|
}
|
|
233
284
|
}
|