diff options
-rw-r--r-- | src/nodejs/main.js | 48 | ||||
-rw-r--r-- | src/nodejs/package.json | 1 | ||||
-rw-r--r-- | src/nodejs/xmlGenerator.js | 10 |
3 files changed, 31 insertions, 28 deletions
diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 71667af..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(config.logLevel); - -log.info("server starting..."); +} function createWayBboxQuery(key, value, left, bottom, right, top) { return { @@ -117,10 +118,12 @@ 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(err.message); - res.writeHead(500,{}); + log.error('message'); + console.log(config['connectionString']); + console.log(err); + res.writeHead(404,{}); res.end(); } else { log.info("db connection was successfull"); @@ -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 97cd2ae..17143a8 100644 --- a/src/nodejs/xmlGenerator.js +++ b/src/nodejs/xmlGenerator.js @@ -26,7 +26,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') @@ -41,14 +41,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 |