1. 合并应用配置
后端开发者背景
开发一个 Node.js 应用,有一份基础的默认配置文件 `default.json`,以及一份针对生产环境的覆盖配置 `production.json`。
问题
需要将生产环境的配置安全地合并到默认配置中,生成最终的运行配置,且不能手动逐个字段复制粘贴。
如何使用
将 `default.json` 的内容粘贴到“目标对象”输入框,将 `production.json` 的内容粘贴到“来源 1”输入框。
目标对象:{"port": 3000, "db": {"host": "localhost", "pool": 5}, "logLevel": "debug"}
来源 1:{"port": 8080, "db": {"host": "prod-db-server"}, "apiKey": "secret123"}结果
得到合并后的配置对象:{"port": 8080, "db": {"host": "prod-db-server"}, "logLevel": "debug", "apiKey": "secret123"}。注意 `db` 对象被整体替换,`port` 被覆盖,`logLevel` 保留,`apiKey` 被新增。