diff --git a/actions/createStaticServer.js b/actions/createStaticServer.js index 5ad99b4..65e33e4 100644 --- a/actions/createStaticServer.js +++ b/actions/createStaticServer.js @@ -5,6 +5,7 @@ var path = require('path'); var npath = require('../utils/nginxPath'); var conf = require('../utils/nginxConf'); var nginxReload = require('../utils/nginxReload'); +var appendToList = require('../utils/listFile').appendToList; var currentPath = path.normalize(process.cwd()); var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows. diff --git a/actions/killServer.js b/actions/killServer.js index 065e9da..01d62d3 100644 --- a/actions/killServer.js +++ b/actions/killServer.js @@ -3,6 +3,7 @@ var shell = require('shelljs'); var npath = require('../utils/nginxPath'); var conf = require('../utils/nginxConf'); var nginxReload = require('../utils/nginxReload'); +var removeFromList = require('../utils/listFile').removeFromList; function killServer(domain, outPort) { shell.rm('-rf', conf(npath.enabledSites(), domain, outPort)); @@ -10,6 +11,7 @@ function killServer(domain, outPort) { shell.rm('-rf', npath.webRootDomain(domain, outPort)); nginxReload(); + removeFromList(domain, outPort); } module.exports = killServer; \ No newline at end of file diff --git a/utils/listFile.js b/utils/listFile.js index ae59f0b..66f19bf 100644 --- a/utils/listFile.js +++ b/utils/listFile.js @@ -31,7 +31,7 @@ function appendToList(domain, outPort, inPort) { jsonFile = JSON.parse(jsonFile); for (block in jsonFile) { - if (block.domain == domain && block.domain.outPort == outPort) { + if (block[domain] == domain && block[domain].outPort == outPort) { delete jsonFile.block; return; } @@ -45,11 +45,6 @@ function appendToList(domain, outPort, inPort) { jsonFile = beautifyJSON(jsonFile); } fs.writeFileSync(listFilePath, jsonFile); - -} - -function readServers () { - return JSON.parse(fs.readFileSync(listFilePath)); } function removeFromList (domain, outPort) { @@ -59,8 +54,9 @@ function removeFromList (domain, outPort) { jsonFile = JSON.parse(jsonFile); for (block in jsonFile) { - if (block.domain == domain && block.domain.outPort == outPort) { + if (block[domain] == domain && block[domain].outPort == outPort) { delete jsonFile.block; + console.log('\nDomain was deleted successfully.\n'); return; } } @@ -73,5 +69,10 @@ function removeFromList (domain, outPort) { fs.writeFileSync(listFilePath, jsonFile); } +function readServers () { + return JSON.parse(fs.readFileSync(listFilePath)); +} + module.exports.appendToList = appendToList; -module.exports.readServers = readServers; \ No newline at end of file +module.exports.readServers = readServers; +module.exports.removeFromList = removeFromList; \ No newline at end of file