diff --git a/index.js b/index.js index cf8e6e7..90fcdc1 100755 --- a/index.js +++ b/index.js @@ -14,9 +14,12 @@ var createProxyServer = require('./actions/createProxyServer'); var createStaticServer = require('./actions/createStaticServer'); var killServer = require('./actions/killServer'); -appendToList("example.com", "80"); -appendToList("example2.com", "80", "4000"); +var jsonFile; +// appendToList("example.com", "80"); +// appendToList("example2.com", "80", "4000"); +// appendToList("example2.com", "80", "4444"); +console.log(jsonFile); // Check for requirements such as OS version and nginx install. Throw and exit if requirements not found. #Roadmap: Add ability to satisfy any possible requirements. requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up` diff --git a/utils/listFile.js b/utils/listFile.js index fc5abdb..2572705 100644 --- a/utils/listFile.js +++ b/utils/listFile.js @@ -7,41 +7,57 @@ var listFilePath = "/etc/up-serve/servers.up"; function appendToList(domain, outPort, inPort) { + var jsonFile = {}; + var domBlock; + if (!inPort) { - var domBlock = { - domain: { + domBlock = { "type": "static", "outPort": outPort, "inPort": undefined - } } } else { - var domBlock = { - domain: { + domBlock = { "type": "proxy", "outPort": outPort, "inPort": inPort - } } } + + jsonFile = { + } + + var newBlock = { + + } +/* + Object.assign(jsonFile, domain.domBlock) + return jsonFile; +*/ + + if (fs.existsSync(listFilePath)) { - var jsonFile = fs.readFileSync(listFilePath); + jsonFile = fs.readFileSync(listFilePath); jsonFile = JSON.parse(jsonFile); for (block in jsonFile) { - if (block.domain == domain && block.outPort == outPort) { + if (block.domain == domain && block.domain.outPort == outPort) { delete jsonFile.block; return; } } - jsonFile.domain = domBlock.domain; + jsonFile[domain] = domBlock; + jsonFile = JSON.stringify(jsonFile); } else { - var jsonFile = JSON.stringify(domBlock) + EOL; + jsonFile = { + } + jsonFile[domain] = domBlock; + jsonFile = JSON.stringify(jsonFile); } fs.writeFileSync(listFilePath, jsonFile); - + } module.exports = appendToList; \ No newline at end of file