aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Engel <mark.c.engel@gmail.com>2011-01-21 19:59:09 +0100
committerMark Engel <mark.c.engel@gmail.com>2011-01-21 19:59:09 +0100
commit8f3aaad7210274d49af81b504cb7fc81158e830a (patch)
treea88193922417d1b1db315c03ba7436b66bedcc74
parent83967abe326c8c76f71d69ba6fe75f5bbdf6a2c0 (diff)
downloadosm-xapi-8f3aaad7210274d49af81b504cb7fc81158e830a.tar.gz
osm-xapi-8f3aaad7210274d49af81b504cb7fc81158e830a.tar.xz
osm-xapi-8f3aaad7210274d49af81b504cb7fc81158e830a.zip
added opts for command line parsing
-rw-r--r--src/nodejs/main.js44
-rw-r--r--src/nodejs/package.json1
-rw-r--r--src/nodejs/xmlGenerator.js10
3 files changed, 29 insertions, 26 deletions
diff --git a/src/nodejs/main.js b/src/nodejs/main.js
index 37e106d..17a5235 100644
--- a/src/nodejs/main.js
+++ b/src/nodejs/main.js
@@ -1,28 +1,29 @@
var clutch = require('clutch');
+var http = require('http');
var pg = require('pg');
var xmlGenerator = require('./xmlGenerator.js');
-
-// load config
+var opts = require('opts');
var config = require('./config.json');
-process.argv.forEach(function (val,index, array){
- if(val=="-c"){
- path = array[index+1];
+var log4js = require('log4js')();
+var log = log4js.getLogger('global');
+
+var options = [
+ { short : 'c'
+ , long : 'config'
+ , description : 'Select configuration file'
+ , value : true
+ , callback : function(value) { loadCustomConfig(value); }
+ }
+];
+
+function loadCustomConfig(path) {
+ log.info("reading custom config: " + path);
if( path[0] != '/'){
path = __dirname + '/' + path;
}
+ log.info(path);
config = require(path);
- }
-});
-var connectionString = config['connectionString'];
-
-//set up logger
-var log4js = require('log4js')(); //note the need to call the function
-//log4js.addAppender(log4js.fileAppender('osm-xapi.log'), 'cheese');
-
-var log = log4js.getLogger('global');
-log.setLevel('ALL');
-
-log.info("server starting...");
+}
function createWayBboxQuery(key, value, left, bottom, right, top) {
return {
@@ -117,9 +118,11 @@ function connectionError(err, res) {
}
function db_connect(res, callback) {
- pg.connect(connectionString, function(err, client) {
+ pg.connect(config['connectionString'], function(err, client) {
if(err) {
log.error('message');
+ console.log(config['connectionString']);
+ console.log(err);
res.writeHead(404,{});
res.end();
} else {
@@ -207,7 +210,8 @@ myRoutes = clutch.route404([
//['GET /api/relation\\[(\\w+)=(\\w+)\\](\\[bbox=(\\d),(\\d),(\\d),(\\d)\\])$',relationBboxHandler],
]);
-
-var http = require('http');
+log.setLevel('ALL');
+log.info("server starting...");
+opts.parse(options, true);
http.createServer(myRoutes).listen(config.port, config.host);
log.info("Started server at " + config.host + ":" + config.port );
diff --git a/src/nodejs/package.json b/src/nodejs/package.json
index ca196f4..97db4eb 100644
--- a/src/nodejs/package.json
+++ b/src/nodejs/package.json
@@ -8,5 +8,6 @@
, "clutch" : "*"
, "xmlbuilder" : "*"
, "log4js" : "*"
+ , "opts" : "*"
}
}
diff --git a/src/nodejs/xmlGenerator.js b/src/nodejs/xmlGenerator.js
index e982e18..5dc0efa 100644
--- a/src/nodejs/xmlGenerator.js
+++ b/src/nodejs/xmlGenerator.js
@@ -24,7 +24,7 @@ exports.createNode = function (row) {
.att('v',escape(temp[x+1]));
}
return builder.toString({ pretty: true });
-}
+};
exports.createWay = function (row) {
var way = builder.begin('way')
@@ -39,14 +39,12 @@ exports.createWay = function (row) {
.att('k',escape(temp[x]))
.att('v',escape(temp[x+1]));
}
-
var temp = row.nodes.replace("{","").replace("}","").split(",");
- for(var x=0;x<temp.length;x++) {
- way.ele('nd')
- .att('ref',temp[x]);
+ for(var i=0;i<temp.length;i++) {
+ way.ele('nd').att('ref',temp[i]);
}
return builder.toString({pretty:'true'});
-}
+};
function toISO8601(date) {
//2007-03-31T00:09:22+01:00