mirror of
https://github.com/mkschreder/juci.git
synced 2025-01-08 11:57:39 +08:00
juci-local-server: Add config with port option
Easy configuration object based on JSON to easily change port number.
This commit is contained in:
parent
c6e23a97c5
commit
ba71ab809e
@ -6,12 +6,34 @@ var JSON = require("JSON");
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var request = require("request");
|
var request = require("request");
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
|
|
||||||
var bodyParser = require('body-parser')
|
var bodyParser = require('body-parser')
|
||||||
|
var configuration ={};
|
||||||
var config = {
|
var config = {
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
|
//check if file exists and is a file
|
||||||
|
if (fs.lstatSync("juci-local-server.config").isFile())
|
||||||
|
{
|
||||||
|
configuration = JSON.parse(fs.readFileSync("juci-local-server.config"));
|
||||||
|
if ( configuration.serverPort == undefined) {
|
||||||
|
throw new Error('ENOENT');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Error('ENOENT');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (e.code = 'ENOENT')
|
||||||
|
{
|
||||||
|
configuration = JSON.parse('{ "serverPort" : "3000" }');
|
||||||
|
} else {
|
||||||
|
throw(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(configuration.serverPort)
|
||||||
for(var i = 0; i < process.argv.length; i++){
|
for(var i = 0; i < process.argv.length; i++){
|
||||||
switch(process.argv[i]){
|
switch(process.argv[i]){
|
||||||
case "--host": config.ubus_uri = "http://"+process.argv[++i]+"/ubus"; break;
|
case "--host": config.ubus_uri = "http://"+process.argv[++i]+"/ubus"; break;
|
||||||
@ -303,7 +325,7 @@ app.post('/ubus', function(req, res) {
|
|||||||
*/
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
var server = app.listen(3000, function () {
|
var server = app.listen(configuration.serverPort, function () {
|
||||||
var host = server.address().address;
|
var host = server.address().address;
|
||||||
var port = server.address().port;
|
var port = server.address().port;
|
||||||
|
|
||||||
|
3
juci-local-server.config.example
Normal file
3
juci-local-server.config.example
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"serverPort" : 3000
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user