mirror of
https://github.com/mkschreder/juci.git
synced 2025-01-09 04:19:29 +08:00
juci-local-server: add port option
This commit is contained in:
parent
ba71ab809e
commit
307216d558
@ -7,44 +7,31 @@ var fs = require("fs");
|
||||
var request = require("request");
|
||||
var http = require("http");
|
||||
var bodyParser = require('body-parser')
|
||||
var configuration ={};
|
||||
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)
|
||||
}
|
||||
var config = { port: 3000 };
|
||||
|
||||
//check if file exists and is a file
|
||||
if (fs.existsSync("juci-local-server.config")){
|
||||
try {
|
||||
config = JSON.parse(fs.readFileSync("juci-local-server.config"));
|
||||
} catch(e){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
console.log(configuration.serverPort)
|
||||
for(var i = 0; i < process.argv.length; i++){
|
||||
switch(process.argv[i]){
|
||||
case "--host": config.ubus_uri = "http://"+process.argv[++i]+"/ubus"; break;
|
||||
case "--port": config.port = parseInt(process.argv[++i]); break;
|
||||
case "--ubus": config.ubus_uri = process.argv[++i]; break;
|
||||
};
|
||||
}
|
||||
|
||||
if(!config.ubus_uri){
|
||||
if(!config.ubus_uri || !config.port){
|
||||
console.log("juci-local-server: ");
|
||||
console.log(" --host <host>");
|
||||
console.log(" specify host to connect to");
|
||||
console.log(" --port <port>");
|
||||
console.log(" specify port to use for local server");
|
||||
console.log(" --ubus <ubus url>");
|
||||
console.log(" specify ubus url directly (https://192.168.1.1/ubus)");
|
||||
process.exit();
|
||||
@ -325,9 +312,9 @@ app.post('/ubus', function(req, res) {
|
||||
*/
|
||||
});
|
||||
|
||||
var server = app.listen(configuration.serverPort, function () {
|
||||
var host = server.address().address;
|
||||
var port = server.address().port;
|
||||
var server = app.listen(config.port, function () {
|
||||
var host = server.address().address;
|
||||
var port = server.address().port;
|
||||
|
||||
for(var i = 0; i < process.argv.length; i++){
|
||||
switch(process.argv[i]){
|
||||
@ -349,6 +336,6 @@ var server = app.listen(configuration.serverPort, function () {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
console.log('Local server listening on http://%s:%s', host, port);
|
||||
console.log('Local server listening on http://%s:%s', host, port);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user