Browse Source

appendToList works

pull/3/head
Muthu Kumar 7 years ago
parent
commit
a3c3b08cc1
  1. 7
      index.js
  2. 38
      utils/listFile.js

7
index.js

@ -14,9 +14,12 @@ var createProxyServer = require('./actions/createProxyServer');
var createStaticServer = require('./actions/createStaticServer'); var createStaticServer = require('./actions/createStaticServer');
var killServer = require('./actions/killServer'); var killServer = require('./actions/killServer');
appendToList("example.com", "80"); var jsonFile;
appendToList("example2.com", "80", "4000"); // 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. // 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` requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up`

38
utils/listFile.js

@ -7,41 +7,57 @@ var listFilePath = "/etc/up-serve/servers.up";
function appendToList(domain, outPort, inPort) { function appendToList(domain, outPort, inPort) {
var jsonFile = {};
var domBlock;
if (!inPort) { if (!inPort) {
var domBlock = { domBlock = {
domain: {
"type": "static", "type": "static",
"outPort": outPort, "outPort": outPort,
"inPort": undefined "inPort": undefined
}
} }
} else { } else {
var domBlock = { domBlock = {
domain: {
"type": "proxy", "type": "proxy",
"outPort": outPort, "outPort": outPort,
"inPort": inPort "inPort": inPort
}
} }
} }
jsonFile = {
}
var newBlock = {
}
/*
Object.assign(jsonFile, domain.domBlock)
return jsonFile;
*/
if (fs.existsSync(listFilePath)) { if (fs.existsSync(listFilePath)) {
var jsonFile = fs.readFileSync(listFilePath); jsonFile = fs.readFileSync(listFilePath);
jsonFile = JSON.parse(jsonFile); jsonFile = JSON.parse(jsonFile);
for (block in jsonFile) { for (block in jsonFile) {
if (block.domain == domain && block.outPort == outPort) { if (block.domain == domain && block.domain.outPort == outPort) {
delete jsonFile.block; delete jsonFile.block;
return; return;
} }
} }
jsonFile.domain = domBlock.domain; jsonFile[domain] = domBlock;
jsonFile = JSON.stringify(jsonFile);
} }
else { else {
var jsonFile = JSON.stringify(domBlock) + EOL; jsonFile = {
}
jsonFile[domain] = domBlock;
jsonFile = JSON.stringify(jsonFile);
} }
fs.writeFileSync(listFilePath, jsonFile); fs.writeFileSync(listFilePath, jsonFile);
} }
module.exports = appendToList; module.exports = appendToList;
Loading…
Cancel
Save