Skip to content
This repository was archived by the owner on Jan 6, 2021. It is now read-only.

Commit b269e20

Browse files
committed
Little refactor, one todo :-)
1 parent 162a6ca commit b269e20

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

app.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ http.createServer(function(request, response) {
104104
};
105105

106106
if(cfg.user) {
107+
//id -u {cfg.user}
107108
spawn_options.uid = cfg.user;
108109
}
109110

110-
if(!fs.readdirSync(cfg.path)) {
111+
try{
112+
fs.readdirSync(cfg.path);
113+
spawn_options.cwd = cfg.path;
114+
} catch(e) {
111115
return log('Invalid path "' + cfg.path + '" in config "' + request.url + '"', request.url + '.error');
112116
}
113-
spawn_options.cwd = cfg.path;
114117

115118
if(cfg.refs){
116119
var refsType = typeof cfg.refs;
@@ -127,23 +130,21 @@ http.createServer(function(request, response) {
127130
if(cfg.commands.length){
128131
var currentCommands = JSON.parse(JSON.stringify(cfg.commands));
129132

130-
var processCommand = function(cmd) {
133+
var spawnCommand = function(cmd) {
131134
var commandString = cmd.join(' ');
132135
var result = child_process.spawn(cmd.shift(), cmd, spawn_options);
133136

134-
result.stdout.on('data', resultCallback(commandString, 'Data from "{command}": {data}', request.url + '.info'));
135-
result.stderr.on('data', resultCallback(commandString, 'Error in "{command}": {data}', request.url + '.error'));
136-
result.on('exit', (function(cmd_string) {
137-
return function(code, signal) {
137+
result.stdout.on('data', stdioCallback(commandString, 'Data from "{command}": {data}', request.url + '.info'));
138+
result.stderr.on('data', stdioCallback(commandString, 'Error in "{command}": {data}', request.url + '.error'));
139+
result.on('exit', function(code, signal) {
138140
var next = currentCommands.shift();
139141
if(next) {
140-
processCommand(next);
142+
spawnCommand(next);
141143
}
142-
};
143-
})(commandString));
144+
});
144145
};
145146

146-
var resultCallback = function(cmd_string, format, file) {
147+
var stdioCallback = function(cmd_string, format, file) {
147148
return function(data) {
148149
log(format.fmt({
149150
command: cmd_string,
@@ -152,7 +153,7 @@ http.createServer(function(request, response) {
152153
};
153154
};
154155

155-
processCommand(currentCommands.shift());
156+
spawnCommand(currentCommands.shift());
156157
} else {
157158
return log('No commands to execute.', request.url + '.info');
158159
}

0 commit comments

Comments
 (0)