Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[讨论] ProxyConfig 当时为什么在保存时去除了 enable ?以及设置 enable 时为什么没有同步保存到本地? #45

Closed
beanlee opened this issue Apr 29, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@beanlee
Copy link
Member

beanlee commented Apr 29, 2020

疑问?

有一个需求,当项目配置 n 个接口代理,亟需一个一键生效所有代理的功能,否则每次启动以后都要手动一个一个点开,但其实看代码 API 内部在写入文件的时候只是过滤掉了这个属性,原本是保存某一个或某一些接口代理状态的功能。

当时为什么在保存时去除了 enabled ?

保存时过滤掉 enabled 属性,保证用户每次启动项目都默认不开启,以免造成困扰吗?

针对这个问题有两个想法:

  • 同步保存 enabled 属性
  • 保存时过滤逻辑保留,提供 enable all 和 disable all 两个按钮

const syncToDisk = () => {
fs.writeFileSync(
CONFIG_FILE,
JSON.stringify(
ruleCache,
(key, value) => {
return key === "enabled" ? undefined : value;
},
" "
),
"utf-8"
);
};

这部分代码,设置 enable 时为什么没有同步保存到本地?

proxyAPI.put("/rule/:ruleId/enabled", (req, res) => {
ruleCache = ruleCache.map(rule => {
if (rule.ruleId === req.params.ruleId) {
return Object.assign({}, rule, { enabled: req.body.enabled });
} else {
return rule;
}
});
res.json({
success: true
});
});

@loveky
Copy link
Member

loveky commented Apr 30, 2020

保存时过滤掉 enabled 属性,保证用户每次启动项目都默认不开启,以免造成困扰吗?

这块儿当时应该考虑的是如果在本地环境里增加enabled字段,用户有可能在启动开发环境的状态下手动修改配置问题,然而直接修改时开发环境是不会生效的,应该是怕造成困扰(也许这个担心是多余的)

保存时过滤逻辑保留,提供 enable all 和 disable all 两个按钮

👍
还可以考虑给start 增加一个参数, --auto-mock

@beanlee
Copy link
Member Author

beanlee commented Apr 30, 2020

OK,打算加按钮这么搞,不过文档上加一行说明,当前修改代理mock的状态并不会同步保存

@beanlee
Copy link
Member Author

beanlee commented Apr 30, 2020

enableall

Tada~

@loveky
Copy link
Member

loveky commented Apr 30, 2020

👏 👏 👏 👏

@beanlee beanlee self-assigned this Apr 30, 2020
@beanlee beanlee added enhancement New feature or request question Further information is requested labels Apr 30, 2020
@loveky loveky closed this as completed May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants