Skip to content

Commit

Permalink
feat: add cmd use/enable
Browse files Browse the repository at this point in the history
  • Loading branch information
avwo committed Jun 15, 2018
1 parent 1044659 commit 8538cb6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 10 additions & 6 deletions bin/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function request(body, callback) {
if (options.username || options.password) {
var auth = [options.username || '', options.password || ''].join(':');
reqOptions.headers = {
'content-type': 'application/x-www-form-urlencoded',
authorization: 'Basic ' + new Buffer(auth).toString('base64')
};
}
Expand All @@ -86,7 +87,7 @@ function request(body, callback) {
if (res.statusCode != 200) {
throw resBody || 'response ' + res.statusCode + ' error';
}
callback(resBody);
callback(JSON.parse(resBody));
});
});
// 不处理错误,直接抛出终止进程
Expand All @@ -102,7 +103,9 @@ module.exports = function(filepath, storage, force) {
var pid;
try {
var config = fse.readJsonSync(configFile);
options = config.options;
options = config.options;
// TODO: xxx
options.port = 8899;
pid = options && config.pid;
} catch(e) {}
isRunning(pid, function(running) {
Expand Down Expand Up @@ -132,15 +135,16 @@ module.exports = function(filepath, storage, force) {
'rules=' + encodeURIComponent(rules)
].join('&');
request(body, function() {
console.log(colors.green('[127.0.0.1:' + port + '] setting successful.'));
console.log(colors.green('setting whistle[127.0.0.1:' + port + '] rules successful.'));
});
};
if (force) {
return setRules();
}
request('name=' + encodeURIComponent(name), function(text) {
if (text) {
console.log(colors.yellow('xxx环境配置不为空,如果需要覆盖当前环境命令行添加参数:--force.'));
request('name=' + encodeURIComponent(name), function(data) {
if (data.rules) {
// TODO:
console.log(colors.yellow('xxx环境配置不为空,如果需要覆盖当前环境命令行添加参数:--force'));
return;
}
setRules();
Expand Down
8 changes: 8 additions & 0 deletions biz/webui/cgi-bin/rules/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var rules = require('../../lib/rules');

module.exports = function(req, res) {
var body = req.body;
console.log(body)
// var result = rules.moveTo(body.from, body.to, body.clientId);
res.json({ ec: 0, rules: 1 });
};

0 comments on commit 8538cb6

Please sign in to comment.