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 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`

38
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;
Loading…
Cancel
Save