Skip to content

chore(brick-container): add --https flag for dev server#4879

Merged
WHChen-Alex merged 1 commit into
v3from
chore/brick-container-https-flag-260513-1645
May 13, 2026
Merged

chore(brick-container): add --https flag for dev server#4879
WHChen-Alex merged 1 commit into
v3from
chore/brick-container-https-flag-260513-1645

Conversation

@panzekun

@panzekun panzekun commented May 13, 2026

Copy link
Copy Markdown
Contributor

依赖检查

组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。

请勾选以下两组选项其中之一:

  • 本次 MR 没有使用上游组件(例如框架、后台组件等)的较新版本提供的特性。

或者:

  • 本次 MR 使用了上游组件(例如框架、后台组件等)的较新版本提供的特性。
  • 在对应的文件中更新了该上游组件的依赖版本(或确认了当前声明的依赖版本已包含本次 MR 使用的新特性)。

提交信息检查

Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。

破坏性变更是针对于下游使用者而言,可以通过本次改动对下游使用者的影响来识别变更类型:

  • 下游使用者不做任何改动,仍可以正常工作时,那么它属于普通变更。
  • 反之,下游使用者不做改动就无法正常工作时,那么它属于破坏性变更。

例如,构件修改了一个属性名,小产品 Storyboard 中需要使用新属性名才能工作,那么它就是破坏性变更。
又例如,构件还没有任何下游使用者,那么它的任何变更都是普通变更。

破坏性变更:

  • ⚠️ 本次 MR 包含破坏性变更的提交,请继续确认以下所有选项:
  • 没有更好的兼容方案,必须做破坏性变更。
  • 使用了 feat 作为提交类型。
  • 标注了 BREAKING CHANGE: 你的变更说明
  • 同时更新了本仓库中所有下游使用者的调用。
  • 同时更新了本仓库中所有下游使用者对该子包的依赖为即将发布的 major 版本。
  • 同时为其它仓库的 Migrating 做好了准备,例如文档或批量改动的方法。
  • 手动验证过破坏性变更在 Migrate 后可以正常工作。
  • 破坏性变更所在的提交没有意外携带其它子包的改动。

新特性:

  • 本次 MR 包含新特性的提交,且该提交不带有破坏性变更,并使用了 feat 作为提交类型。
  • 给新特性添加了单元测试。
  • 手动验证过新特性可以正常工作。

问题修复:

  • 本次 MR 包含问题修复的提交,且该提交不带有新特性或破坏性变更,并使用了 fix 作为提交类型。
  • 给问题修复添加了单元测试。
  • 手动验证过问题修复得到解决。

杂项工作:

即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:

  • 本次 MR 包含杂项工作的提交,且该提交不带有问题修复、新特性或破坏性变更,并使用了 chore, docs, test 等作为提交类型。

Summary by CodeRabbit

  • 新功能
    • 新增 --https 命令行标志,支持启用 HTTPS 服务
    • 未提供 HTTPS 配置时,自动生成自签名证书

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

Walkthrough

向CLI添加--https标志以启用HTTPS服务。当启用此标志且HTTPS未在配置中时,自动使用openssl生成包含localhost和配置host的SAN的自签名证书对。

Changes

HTTPS自签名证书生成

Layer / File(s) Summary
CLI标志定义与环境提取
packages/brick-container/serve/env.js
在CLI使用文本中添加--https选项,在meow标志配置中引入https布尔值标志,使运行时能够接收和识别HTTPS请求。
证书自动生成与环境初始化
packages/brick-container/serve/env.js
getEnv函数中实现条件逻辑:当HTTPS未预配置且flags.https启用时,使用openssllocalhost和配置的--host生成自签名证书和密钥文件,将生成的文件内容填充到https环境对象中供下游服务逻辑使用。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR描述基本完整,填写了依赖检查和提交信息检查的必要部分,但新特性部分的测试确认未勾选。 请确认是否已为新的--https功能添加了单元测试。如果PR包含的是新特性而非问题修复,需要勾选新特性部分的所有必要项。
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地描述了 PR 的主要变更,即为开发服务器添加 --https 标志。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/brick-container-https-flag-260513-1645

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/brick-container/serve/env.js (1)

136-153: 💤 Low value

避免误把开发证书私钥提交进仓库。

dev-https.key / dev-https.cert 默认生成在 rootDir,若使用方未在 .gitignore 中忽略,私钥极易被一同提交。建议在文档/README 中说明,或在该流程中自动写入/校验项目的 .gitignore,至少在生成时输出一行提示用户将其加入忽略列表。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/brick-container/serve/env.js` around lines 136 - 153, The dev
cert/key are written to rootDir as dev-https.key / dev-https.cert
(keyPath/certPath) and may be accidentally committed; update the HTTPS
generation flow in env.js to either (a) check the project's .gitignore and
append "dev-https.key" and "dev-https.cert" if missing, or (b) at minimum print
a clear one-line warning after generation advising the user to add those
filenames to .gitignore; locate the logic around keyPath/certPath and the
execSync generation block and implement the .gitignore check/append or the
warning message there so users are prompted immediately when files are created.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/brick-container/serve/env.js`:
- Around line 135-153: The SAN generation treats any non-"localhost" host as an
IP and interpolates it as IP:..., causing invalid SANs and potential command
injection; update the logic around the used variables keyPath, certPath and san
(where san is built from flags.host) to: validate and classify flags.host as
IPv4/IPv6 (use a regex or net.isIP) to choose "IP:" vs "DNS:", escape or
strictly validate hostnames (reject unsafe chars/wildcards), replace execSync
shell interpolation with execFileSync/execFile and pass openssl args as an array
(or otherwise escape paths) when calling openssl to generate the cert, and wrap
the child process call in try/catch to detect missing openssl and emit a clear
error message before exiting; leave reading keyPath/certPath and assigning
https.key/https.cert unchanged.

---

Nitpick comments:
In `@packages/brick-container/serve/env.js`:
- Around line 136-153: The dev cert/key are written to rootDir as dev-https.key
/ dev-https.cert (keyPath/certPath) and may be accidentally committed; update
the HTTPS generation flow in env.js to either (a) check the project's .gitignore
and append "dev-https.key" and "dev-https.cert" if missing, or (b) at minimum
print a clear one-line warning after generation advising the user to add those
filenames to .gitignore; locate the logic around keyPath/certPath and the
execSync generation block and implement the .gitignore check/append or the
warning message there so users are prompted immediately when files are created.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3b36f65-7326-4ec0-b7a7-5d086b518f73

📥 Commits

Reviewing files that changed from the base of the PR and between 342bc65 and abfd238.

📒 Files selected for processing (1)
  • packages/brick-container/serve/env.js

Comment on lines +135 to +153
if (!https && flags.https) {
const keyPath = path.join(rootDir, "dev-https.key");
const certPath = path.join(rootDir, "dev-https.cert");

if (!existsSync(keyPath) || !existsSync(certPath)) {
const { execSync } = await import("node:child_process");
const san = `DNS:localhost${flags.host !== "localhost" ? ",IP:" + flags.host : ""}`;
console.log(chalk.cyan("Auto-generating self-signed certificate..."));
execSync(
`openssl req -x509 -newkey rsa:2048 -keyout "${keyPath}" -out "${certPath}" -days 365 -nodes -subj "/CN=localhost" -addext "subjectAltName=${san}"`,
{ stdio: "inherit" }
);
}

https = {
key: readFileSync(keyPath, "utf8"),
cert: readFileSync(certPath, "utf8"),
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

SAN 生成逻辑对非 IP 主机名会产生无效证书。

第 141 行 DNS:localhost${flags.host !== "localhost" ? ",IP:" + flags.host : ""} 把所有非 localhost--host 值都当成 IP 处理。但 --host 完全可能是一个 DNS 名(如 dev.localmydev*.local),此时生成的 SAN 是 IP:dev.local,openssl 会报错或生成的证书与浏览器实际访问的主机名不匹配,导致 HTTPS 校验失败。建议根据是否匹配 IPv4/IPv6 字面量来区分 DNS:IP:

此外该 openssl 命令将 flags.hostkeyPathcertPath 直接拼接进 shell 字符串,若 rootDir--host 含空格/shell 元字符,会出现命令注入或执行失败;建议用 execFileSync 配合参数数组,或对 host 做严格校验。同时缺少 openssl 不存在时的友好错误提示(Windows 上较常见)。

🛠️ 建议修复
     if (!existsSync(keyPath) || !existsSync(certPath)) {
-      const { execSync } = await import("node:child_process");
-      const san = `DNS:localhost${flags.host !== "localhost" ? ",IP:" + flags.host : ""}`;
-      console.log(chalk.cyan("Auto-generating self-signed certificate..."));
-      execSync(
-        `openssl req -x509 -newkey rsa:2048 -keyout "${keyPath}" -out "${certPath}" -days 365 -nodes -subj "/CN=localhost" -addext "subjectAltName=${san}"`,
-        { stdio: "inherit" }
-      );
+      const { execFileSync } = await import("node:child_process");
+      const isIPv4 = (h) => /^(\d{1,3}\.){3}\d{1,3}$/.test(h);
+      const isIPv6 = (h) => h.includes(":");
+      const sanEntries = ["DNS:localhost"];
+      if (flags.host && flags.host !== "localhost") {
+        sanEntries.push(
+          (isIPv4(flags.host) || isIPv6(flags.host) ? "IP:" : "DNS:") + flags.host
+        );
+      }
+      console.log(chalk.cyan("Auto-generating self-signed certificate..."));
+      try {
+        execFileSync(
+          "openssl",
+          [
+            "req", "-x509", "-newkey", "rsa:2048",
+            "-keyout", keyPath, "-out", certPath,
+            "-days", "365", "-nodes",
+            "-subj", "/CN=localhost",
+            "-addext", `subjectAltName=${sanEntries.join(",")}`,
+          ],
+          { stdio: "inherit" }
+        );
+      } catch (err) {
+        console.error(
+          chalk.red("Failed to generate self-signed certificate. Is `openssl` installed and on PATH?")
+        );
+        throw err;
+      }
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/brick-container/serve/env.js` around lines 135 - 153, The SAN
generation treats any non-"localhost" host as an IP and interpolates it as
IP:..., causing invalid SANs and potential command injection; update the logic
around the used variables keyPath, certPath and san (where san is built from
flags.host) to: validate and classify flags.host as IPv4/IPv6 (use a regex or
net.isIP) to choose "IP:" vs "DNS:", escape or strictly validate hostnames
(reject unsafe chars/wildcards), replace execSync shell interpolation with
execFileSync/execFile and pass openssl args as an array (or otherwise escape
paths) when calling openssl to generate the cert, and wrap the child process
call in try/catch to detect missing openssl and emit a clear error message
before exiting; leave reading keyPath/certPath and assigning
https.key/https.cert unchanged.

@cypress

cypress Bot commented May 13, 2026

Copy link
Copy Markdown

next-core    Run #12027

Run Properties:  status check passed Passed #12027  •  git commit bc4f73d95d ℹ️: Merge abfd238a490134053e0c5f21a3af221082e70ae2 into 342bc655e525ebdef40b0ed012bc...
Project next-core
Branch Review chore/brick-container-https-flag-260513-1645
Run status status check passed Passed #12027
Run duration 00m 27s
Commit git commit bc4f73d95d ℹ️: Merge abfd238a490134053e0c5f21a3af221082e70ae2 into 342bc655e525ebdef40b0ed012bc...
Committer 吃猫的鱼
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 17
View all changes introduced in this branch ↗︎

@WHChen-Alex WHChen-Alex merged commit eeb2b51 into v3 May 13, 2026
9 checks passed
@WHChen-Alex WHChen-Alex deleted the chore/brick-container-https-flag-260513-1645 branch May 13, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants