You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode:能否在serverReadyAction中同时启动两个URL?

在VSCode单个启动配置中同时打开两个URL的实现方法

答案是:没法直接通过原生的openUrl选项打开多个URL,但可以用自定义命令的方式实现,比compounds配置更直接。

具体实现步骤如下:

  • 首先确保你的.vscode/tasks.json里已经配置好启动Redis Insights的Docker Compose预启动任务,比如:

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "docker-compose-up",
          "type": "shell",
          "command": "docker-compose up -d",
          "isBackground": true,
          "problemMatcher": {
            "pattern": {
              "regexp": "."
            },
            "background": {
              "activeOnStart": true,
              "beginsPattern": "Starting.*",
              "endsPattern": "started.*"
            }
          }
        }
      ]
    }
    
  • 然后在.vscode/launch.json的单个启动配置中,利用serverReadyAction的command字段执行多URL打开命令,替代默认的openUrl:

    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "启动API并打开Swagger+Redis Insights",
          "type": "node", // 根据你的API类型修改,比如python、dotnet等
          "request": "launch",
          "preLaunchTask": "docker-compose-up", // 指定预启动的Docker Compose任务
          "program": "${workspaceFolder}/src/index.js", // 你的API入口文件路径
          "serverReadyAction": {
            "pattern": "API server running on port (\\d+)", // 匹配API启动成功的日志,需根据实际日志调整
            // Windows环境下的命令
            "command": "start http://localhost:$1/swagger && start http://localhost:8001",
            // Mac/Linux环境替换为下面的命令
            // "command": "open http://localhost:$1/swagger && open http://localhost:8001"
          }
        }
      ]
    }
    

关键说明:

  1. 日志匹配:pattern字段的正则需要能匹配到API启动完成的日志,其中(\\d+)用于捕获API的端口号(如果端口固定,也可以直接写死URL,不用捕获)。
  2. 跨平台命令:不同系统打开URL的命令不同,Windows用start,Mac用open,Linux用xdg-open,按需替换。
  3. 优势:这种方式无需配置compounds,在单个启动项里就能完成预启动任务、启动API、同时打开两个URL的全部流程,比compounds更直接。

内容的提问来源于stack exchange,提问作者Vinicius Andrade

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 14:17:19