@next-core/brick-container 2.71.3 → 2.71.6

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/serve/serve.js CHANGED
@@ -26,6 +26,8 @@ module.exports = function serve(runtimeFlags) {
26
26
 
27
27
  let cachedIndexHtml;
28
28
 
29
+ const standaloneAppRoot = env.standaloneAppRoot;
30
+
29
31
  const serveIndexHtml = (_req, res) => {
30
32
  if (!cachedIndexHtml) {
31
33
  const indexHtml = path.join(distDir, "index.html");
@@ -48,7 +50,7 @@ module.exports = function serve(runtimeFlags) {
48
50
  escapeRegExp("<!--# echo var='app_root' default='' -->"),
49
51
  "g"
50
52
  ),
51
- env.standaloneMicroApps ? env.standaloneAppDir : ""
53
+ standaloneAppRoot
52
54
  )
53
55
  .replace(
54
56
  new RegExp(
@@ -56,7 +58,7 @@ module.exports = function serve(runtimeFlags) {
56
58
  "g"
57
59
  ),
58
60
  `${env.publicCdn ?? ""}${
59
- env.standaloneMicroApps ? `${env.standaloneAppDir}-/core/` : ""
61
+ env.standaloneMicroApps ? `${standaloneAppRoot}-/core/` : ""
60
62
  }`
61
63
  )
62
64
  .replace(
@@ -82,11 +84,11 @@ module.exports = function serve(runtimeFlags) {
82
84
  "((w)=>{",
83
85
  [
84
86
  "w.STANDALONE_MICRO_APPS=!0",
85
- `var a=w.APP_ROOT=${JSON.stringify(env.standaloneAppDir)}`,
87
+ `var a=w.APP_ROOT=${JSON.stringify(standaloneAppRoot)}`,
86
88
  `var d=a+"-/"`,
87
89
  'var p=w.PUBLIC_ROOT=(w.PUBLIC_CDN||"")+d',
88
90
  'w.CORE_ROOT=p+"core/"',
89
- `w.BOOTSTRAP_FILE=d+"bootstrap.hash.json"`,
91
+ `w.BOOTSTRAP_FILE=d+"bootstrap.${env.bootstrapHash}.json"`,
90
92
  ]
91
93
  .filter(Boolean)
92
94
  .join(";"),
@@ -103,9 +105,9 @@ module.exports = function serve(runtimeFlags) {
103
105
  res.send(cachedIndexHtml);
104
106
  };
105
107
 
106
- if (env.standaloneMicroApps) {
108
+ if (env.standaloneMicroApps && !env.useRemote) {
107
109
  // Return a fake `conf.yaml` for standalone micro-apps.
108
- app.get(`${env.baseHref}conf.yaml`, (req, res) => {
110
+ app.get(`${standaloneAppRoot}conf.yaml`, (req, res) => {
109
111
  res.setHeader("content-type", "text/plain");
110
112
  res.send(
111
113
  yaml.safeDump({
@@ -151,7 +153,7 @@ module.exports = function serve(runtimeFlags) {
151
153
 
152
154
  // Serve static files.
153
155
  const staticRoot = env.standaloneMicroApps
154
- ? `${serveRoot}-/core/`
156
+ ? `${standaloneAppRoot || serveRoot}-/core/`
155
157
  : serveRoot;
156
158
  app.use(staticRoot, express.static(distDir));
157
159
  }
@@ -199,15 +201,17 @@ module.exports = function serve(runtimeFlags) {
199
201
  })
200
202
  );
201
203
 
202
- app.all(
203
- /^(?!\/next\/).+/,
204
- createProxyMiddleware({
205
- target: env.consoleServer,
206
- secure: false,
207
- changeOrigin: true,
208
- logLevel: "warn",
209
- })
210
- );
204
+ if (env.legacyConsole) {
205
+ app.all(
206
+ new RegExp(`^(?!${escapeRegExp(env.baseHref)}).+`),
207
+ createProxyMiddleware({
208
+ target: env.consoleServer,
209
+ secure: false,
210
+ changeOrigin: true,
211
+ logLevel: "warn",
212
+ })
213
+ );
214
+ }
211
215
  }
212
216
  }
213
217
 
@@ -1,4 +1,5 @@
1
1
  const path = require("path");
2
+ const fs = require("fs-extra");
2
3
  const bodyParser = require("body-parser");
3
4
  const { escapeRegExp } = require("lodash");
4
5
  const {
@@ -28,14 +29,12 @@ module.exports = (env, app) => {
28
29
  mockedMicroAppsDir,
29
30
  mockedMicroApps,
30
31
  standaloneMicroApps,
31
- standaloneAppDir,
32
+ standaloneAppRoot,
32
33
  asCdn,
33
34
  } = env;
34
35
  let username;
35
36
 
36
- const publicRoot = standaloneMicroApps
37
- ? `${baseHref}${standaloneAppDir}-/`
38
- : baseHref;
37
+ const publicRoot = standaloneMicroApps ? `${standaloneAppRoot}-/` : baseHref;
39
38
 
40
39
  // 开发时默认拦截 bootstrap 请求。
41
40
  // 如果设定 `REMOTE=true`,则透传远端请求。