@next-core/brick-container 3.6.10 → 3.6.12

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/index.d.ts ADDED
@@ -0,0 +1,91 @@
1
+ import { RequestHandler } from "express";
2
+
3
+ export interface DevConfig {
4
+ /**
5
+ * 设置用于查找本地构件包的文件夹。
6
+ *
7
+ * @default ["node_modules/@next-bricks","node_modules/@bricks"]
8
+ *
9
+ * @example
10
+ *
11
+ * ```js
12
+ * export default {
13
+ * brickFolders: [
14
+ * "node_modules/@next-bricks",
15
+ * "node_modules/@bricks",
16
+ * "../next-*\/bricks",
17
+ * ]
18
+ * }
19
+ * ```
20
+ */
21
+ brickFolders?: string[];
22
+
23
+ /**
24
+ * 服务端设置(特性开关和杂项配置等)
25
+ *
26
+ * @example
27
+ * ```js
28
+ * export default {
29
+ * settings: {
30
+ * featureFlags: {
31
+ * "my-flag": true,
32
+ * }
33
+ * misc: {
34
+ * "myMisc": "anything",
35
+ * },
36
+ * },
37
+ * }
38
+ * ```
39
+ */
40
+ settings?: Settings;
41
+
42
+ /**
43
+ * 微应用配置
44
+ *
45
+ * @example
46
+ * ```js
47
+ * export default {
48
+ * userConfigByApps: {
49
+ * "my-app-id": {
50
+ * myAnyAppConfig: "anything",
51
+ * },
52
+ * },
53
+ * }
54
+ * ```
55
+ */
56
+ userConfigByApps?: UserConfigByApps;
57
+
58
+ /**
59
+ * API mocks
60
+ *
61
+ * @example
62
+ * ```js
63
+ * export default {
64
+ * mocks: [
65
+ * (req, res, next) => {
66
+ * switch (`${req.method} ${req.path}`) {
67
+ * case "GET /api/my-any-api":
68
+ * res.send("fake response");
69
+ * return;
70
+ * case "GET /api/my-another-api":
71
+ * res.send("another fake response");
72
+ * return;
73
+ * }
74
+ * next();
75
+ * }
76
+ * ]
77
+ * }
78
+ * ```
79
+ */
80
+ mocks?: RequestHandler[];
81
+ }
82
+
83
+ interface Settings {
84
+ /** 特性开关 */
85
+ featureFlags?: Record<string, boolean>;
86
+ /** 杂项配置 */
87
+ misc?: Record<string, unknown>;
88
+ [k: string]: unknown;
89
+ }
90
+
91
+ type UserConfigByApps = Record<string, Record<string, unknown>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-core/brick-container",
3
- "version": "3.6.10",
3
+ "version": "3.6.12",
4
4
  "description": "Brick Container Server",
5
5
  "homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/brick-container",
6
6
  "license": "GPL-3.0",
@@ -14,8 +14,15 @@
14
14
  "deploy",
15
15
  "dist",
16
16
  "tools",
17
- "serve"
17
+ "serve",
18
+ "index.d.ts"
18
19
  ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./index.d.ts"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
19
26
  "repository": {
20
27
  "type": "git",
21
28
  "url": "git@github.com:easyops-cn/next-core.git"
@@ -65,5 +72,5 @@
65
72
  "@next-core/runtime": "*",
66
73
  "@next-core/utils": "*"
67
74
  },
68
- "gitHead": "70bf6b500764afe0d97a7d8360f1407b92ad54a2"
75
+ "gitHead": "b7439ff425770820937f2222b034808d6105b676"
69
76
  }
package/serve/env.js CHANGED
@@ -100,6 +100,7 @@ export async function getEnv(rootDir, runtimeFlags) {
100
100
  let brickFolders = ["node_modules/@next-bricks", "node_modules/@bricks"];
101
101
  const devConfigMjs = path.join(rootDir, "dev.config.mjs");
102
102
  let configuredBrickFolders = false;
103
+ let userConfigByApps;
103
104
  if (existsSync(devConfigMjs)) {
104
105
  const devConfig = (await import(devConfigMjs)).default;
105
106
  if (devConfig) {
@@ -109,6 +110,7 @@ export async function getEnv(rootDir, runtimeFlags) {
109
110
  }
110
111
  localSettings = devConfig.settings;
111
112
  localMocks = devConfig.mocks;
113
+ userConfigByApps = devConfig.userConfigByApps;
112
114
  }
113
115
  }
114
116
 
@@ -139,6 +141,7 @@ export async function getEnv(rootDir, runtimeFlags) {
139
141
  cookieSameSiteNone: flags.cookieSameSiteNone,
140
142
  liveReload: flags.liveReload,
141
143
  localSettings,
144
+ userConfigByApps,
142
145
  port: Number(flags.port),
143
146
  wsPort: Number(flags.wsPort),
144
147
  server: getServerPath(flags.server),
@@ -167,6 +170,11 @@ export async function getEnv(rootDir, runtimeFlags) {
167
170
  console.log("local settings: enabled");
168
171
  }
169
172
 
173
+ const configuredApps = Object.keys(userConfigByApps ?? {});
174
+ if (configuredApps.length) {
175
+ console.log(`Override user config for apps: ${configuredApps.join(", ")}`);
176
+ }
177
+
170
178
  if (localMocks?.length) {
171
179
  console.log("local mock: enabled");
172
180
  }
package/serve/getProxy.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { responseInterceptor } from "http-proxy-middleware";
2
2
  import _ from "lodash";
3
+ import jsYaml from "js-yaml";
3
4
  import { getBrickPackages } from "@next-core/serve-helpers";
4
5
  import { getStoryboards } from "./utils/getStoryboards.js";
5
6
  import { fixV2Storyboard } from "./utils/fixV2Storyboard.js";
6
7
  import { injectIndexHtml } from "./utils/injectIndexHtml.js";
7
8
  import { concatBrickPackages } from "./utils/concatBrickPackages.js";
8
9
 
10
+ const { safeDump, JSON_SCHEMA } = jsYaml;
11
+
9
12
  export default function getProxy(env, getRawIndexHtml) {
10
13
  const {
11
14
  rootDir,
@@ -15,6 +18,7 @@ export default function getProxy(env, getRawIndexHtml) {
15
18
  useLocalContainer,
16
19
  localBricks,
17
20
  localBrickFolders,
21
+ userConfigByApps,
18
22
  } = env;
19
23
  if (useRemote) {
20
24
  return [
@@ -151,7 +155,10 @@ export default function getProxy(env, getRawIndexHtml) {
151
155
  );
152
156
  return responseBuffer;
153
157
  }
154
- if (res.statusCode !== 200 && req.method !== "GET") {
158
+ if (
159
+ res.statusCode < 200 ||
160
+ (res.statusCode >= 300 && req.method !== "GET")
161
+ ) {
155
162
  return responseBuffer;
156
163
  }
157
164
  if ((res.getHeader("content-type") || "").includes("text/html")) {
@@ -266,6 +273,32 @@ export default function getProxy(env, getRawIndexHtml) {
266
273
  console.error("Stub bootstrap.json failed:", error);
267
274
  }
268
275
  }
276
+
277
+ if (
278
+ /^\/next\/sa-static\/[^/]+\/versions\/[^/]+\/webroot\/conf\.yaml$/.test(
279
+ req.path
280
+ ) ||
281
+ /^\/next\/[^/]+\/conf\.yaml$/.test(req.path)
282
+ ) {
283
+ removeCacheHeaders(res);
284
+ if (userConfigByApps) {
285
+ if (res.statusCode === 204) {
286
+ res.statusCode = 200;
287
+ res.statusMessage = "OK";
288
+ }
289
+ const conf = {
290
+ user_config_by_apps: userConfigByApps,
291
+ };
292
+ return safeDump(conf, {
293
+ indent: 2,
294
+ schema: JSON_SCHEMA,
295
+ skipInvalid: true,
296
+ noRefs: true,
297
+ noCompatMode: true,
298
+ });
299
+ }
300
+ }
301
+
269
302
  return responseBuffer;
270
303
  }
271
304
  ),
@@ -1,10 +1,13 @@
1
1
  import express from "express";
2
+ import jsYaml from "js-yaml";
2
3
  import bootstrapJson from "./bootstrapJson.js";
3
4
  import mockAuth from "./mockAuth.js";
4
5
  import singleAppBootstrapJson from "./singleAppBootstrapJson.js";
5
6
  import standaloneBootstrapJson from "./standaloneBootstrapJson.js";
6
7
  import serveBricksWithVersions from "./serveBricksWithVersions.js";
7
8
 
9
+ const { safeDump, JSON_SCHEMA } = jsYaml;
10
+
8
11
  export function getMiddlewares(env) {
9
12
  const { baseHref, useRemote, localMicroApps } = env;
10
13
 
@@ -18,13 +21,6 @@ export function getMiddlewares(env) {
18
21
  path: `${baseHref}sa-static/${appId}/versions/0.0.0/webroot/-/bootstrap.hash.json`,
19
22
  middleware: standaloneBootstrapJson(env, appId),
20
23
  });
21
- middlewares.push({
22
- path: `${baseHref}sa-static/${appId}/versions/0.0.0/webroot/conf.yaml`,
23
- middleware(req, res) {
24
- res.status(204);
25
- res.send();
26
- },
27
- });
28
24
  }
29
25
 
30
26
  if (!useRemote) {
@@ -53,7 +49,7 @@ export function getMiddlewares(env) {
53
49
  }
54
50
 
55
51
  export function getPreMiddlewares(env) {
56
- const { baseHref, localMicroApps, localBrickFolders } = env;
52
+ const { baseHref, localMicroApps, localBrickFolders, userConfigByApps } = env;
57
53
 
58
54
  /**
59
55
  * @type {import("webpack-dev-server").Middleware[]}
@@ -65,6 +61,28 @@ export function getPreMiddlewares(env) {
65
61
  path: `${baseHref}api/auth/v2/bootstrap/${appId}`,
66
62
  middleware: singleAppBootstrapJson(env, appId),
67
63
  });
64
+ middlewares.push({
65
+ path: `${baseHref}sa-static/${appId}/versions/0.0.0/webroot/conf.yaml`,
66
+ middleware(req, res) {
67
+ if (userConfigByApps) {
68
+ const conf = {
69
+ user_config_by_apps: userConfigByApps,
70
+ };
71
+ const content = safeDump(conf, {
72
+ indent: 2,
73
+ schema: JSON_SCHEMA,
74
+ skipInvalid: true,
75
+ noRefs: true,
76
+ noCompatMode: true,
77
+ });
78
+ res.type(".yaml");
79
+ res.send(content);
80
+ } else {
81
+ res.status(204);
82
+ res.send();
83
+ }
84
+ },
85
+ });
68
86
  }
69
87
 
70
88
  middlewares.push({