diff options
Diffstat (limited to '')
-rw-r--r-- | src/nodejs/no1.js | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index c31bc5f..104966f 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -20,10 +20,13 @@ var connectionString = config['connectionString']; var log4js = require('log4js')(); //note the need to call the function //log4js.addAppender(log4js.fileAppender('osm-xapi.log'), 'cheese'); -var logger = log4js.getLogger('global'); -logger.setLevel('ALL'); +var util = require('util'); -logger.info("server starting..."); + +var log = log4js.getLogger('global'); +log.setLevel('ALL'); + +log.info("server starting..."); function toISO8601(date) { //2007-03-31T00:09:22+01:00 @@ -67,14 +70,14 @@ function nodeWorldHandler(req, res, key, value) { } function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { - console.log("nodeBboxHandler"); + log.error("nodeBboxHandler"); db_connect(res, function(client) { - console.log(createNodeBboxQuery(key, value, left, bottom, right, top)); + log.info(createNodeBboxQuery(key, value, left, bottom, right, top)); var success = false; var query = client.query(createNodeBboxQuery(key, value, left, bottom, right, top)); query.on('error', function(err) { - console.log(err); + log.error(err); res.writeHead(404,{}); res.end('\n'); }); @@ -99,13 +102,15 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write("<xml>"); } + res.write(createXmlFromRow(row)); + }); }); } function createXmlFromRow(row) { - console.log(row); + log.debug(row); var node = builder.begin('node') .att('id', row.id) .att('timestamp', toISO8601(row.tstamp)) @@ -128,18 +133,18 @@ function wayWorldHandler(req, res, key, value) { } function connectionError(err, res) { - console.log(err); - console.log("foobar"); + log.error(err); + log.fatal("connectionError not implemented"); } function db_connect(res, callback) { pg.connect(connectionString, function(err, client) { if(err) { - console.log(err['message']); + log.error('message'); res.writeHead(404,{}); res.end(); } else { - console.log("db connection was successfull"); + log.info("db connection was successfull"); callback(client); } }); @@ -153,7 +158,7 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { var query = client.query(createWayBboxQuery(key, value, left, bottom, right, top)); query.on('error', function(err) { - console.log(err); + log.error(err); res.writeHead(404,{}); res.end(); }); @@ -192,7 +197,26 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { res.end(); }); subquery.on('row', function(row) { +<<<<<<< HEAD + log.debug(row); + var node = builder.begin('node') + .att('id', row.id) + .att('timetamp', toISO8601(row.tstamp)) + .att('version', row.version) + .att('changeset', row.changeset_id) + .att('lat', row.lat) + .att('lon', row.lon); + if(row.tags != '{}') { + var temp = row.tags.replace("{","").replace("}","").split(","); + for(var x=0;x<temp.length;x=x+2) + node.ele('tag') + .att('k',escape(temp[x])) + .att('v',escape(temp[x+1])); + } + res.write(builder.toString({pretty:'true'})); +======= res.write(createXmlFromRow(row)); +>>>>>>> be4bf1e3bc92921c502508072cd75196238a3fca }); //console.log(createNodesForWayQuery(row.nodes)); @@ -245,4 +269,4 @@ myRoutes = clutch.route404([ var http = require('http'); http.createServer(myRoutes).listen(config.port, config.host); -logger.info("Started server at " + config.host + ":" + config.port ); +log.info("Started server at " + config.host + ":" + config.port ); |