Skip to content

Commit

Permalink
fix(reload): relaod
Browse files Browse the repository at this point in the history
去掉多余的toString调用#73
  • Loading branch information
huangyoukun authored and RobinzZH committed May 29, 2018
1 parent e6406a2 commit 4bcacb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
23 changes: 12 additions & 11 deletions bin/proxy/admin.actions.js
Expand Up @@ -57,36 +57,37 @@ module.exports = {

cp.exec('./check.js', {
timeout: 5000,
encoding: 'utf8',
cwd: __dirname
}, function (err, stdout, stderr) {
let hasError = false;
let errMessage = '';
if (err) {
hasError = true;
errMessage = err.stack;
logger.error(err.stack);
}

if (stderr && stderr.length > 0) {
hasError = true;
logger.error(stderr.toString('UTF-8'));
if (stderr) {
errMessage = stderr;
logger.error(stderr);
}

if (hasError) {
if (errMessage) {
// 异常情况下,不能直接res.end(),需要模拟http异常,让shell感知到异常
res.writeHead(200, { 'Content-Type': 'text/plain; charset=UTF-8' });
res.write(stderr.toString('UTF-8'));
res.write(errMessage);

res.socket && res.socket.end();
return;
}

if (stdout && stdout.length > 0) {
logger.info(stdout.toString('UTF-8'));
if (stdout) {
logger.info(stdout);

// 开始reload
// 开始执行reload
process.emit('reload', req.GET);

res.writeHead(200, { 'Content-Type': 'text/plain; charset=UTF-8' });
res.write(stderr.toString('UTF-8'));
res.write(stdout);
res.end('\r\ndone!\r\n');

return;
Expand Down
1 change: 0 additions & 1 deletion bin/proxy/check.js
Expand Up @@ -15,7 +15,6 @@ try {
const config = plug('config');

process.stdout.write('typeof config: ' + typeof config + '\r\n');

process.stdout.write('check config ok');
process.stdout.write('\r\n');

Expand Down

0 comments on commit 4bcacb2

Please sign in to comment.