diff options
author | Philipp Borgers <borgers@mi.fu-berlin.de> | 2011-01-13 01:49:48 +0100 |
---|---|---|
committer | Philipp Borgers <borgers@mi.fu-berlin.de> | 2011-01-13 01:49:48 +0100 |
commit | 7d9e6e0d1bd45bedc030a287330c50cde7769f56 (patch) | |
tree | dcd5022ad83e47cb066bdfa199b989bfde23c765 /src/nodejs | |
parent | 2d370398fe8b2329736d839504999186a1aee0aa (diff) | |
download | osm-xapi-7d9e6e0d1bd45bedc030a287330c50cde7769f56.tar.gz osm-xapi-7d9e6e0d1bd45bedc030a287330c50cde7769f56.tar.xz osm-xapi-7d9e6e0d1bd45bedc030a287330c50cde7769f56.zip |
fuck you regex... database request possible. we have to learn regex!!!
Diffstat (limited to '')
-rw-r--r-- | src/nodejs/no1.js | 82 |
1 files changed, 75 insertions, 7 deletions
diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index feb3dfb..1a250be 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -1,17 +1,85 @@ + var clutch = require('clutch'); +var pg = require('pg') + +var connectionString = "pg://user:password@host/database"; + + +function createNodeBboxQuery(key, value, left, bottom, right, top) { + return "SELECT * from nodes WHERE (tags @> '\"" + key + + "\"=>\"" + value + "\"'" + + " AND POINT(geom) @ polygon(box('(" + left + + "," + bottom +")'::point,'(" + + + right + "," + top + ")'::point)));"; +} + + + +function nodeWorldHandler(req, res, key, value) { + + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(' key:' +key +' value:'+value+'\n'); +} +function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { + pg.connect(connectionString, function(err,client) { + + if (err) { + console.log(err); + } + else { + console.log(createNodeBboxQuery(key, value, left, bottom, right, top)); + /*client.query(createNodeBboxQuery(key, value, left, bottom, right, top), function(err,result) { + + if (err) { + console.log(err); + } + else { + console.log(result.rows); + for(row in result.rows.length) { + console.log(row); + } + } + });*/ + } + + + + }); + + + + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end( 'bbox: '+ left + bottom + right + top + ' key:' +key +' value:'+value+'!\n'); +} + +function wayWorldHandler(req, res, key, value) { + + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(' key:' +key +' value:'+value+'!\n'); +} +function wayBboxHandler(req, res, key, value, bbox, left, bottom, right, top) { +} -function helloSomeone(req, res, name,bbox, key, value) { +function relationWorldHandler(req, res, key, value) { + res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('obj:'+name+ ' bbox: '+ bbox + ' key:' +key +' value:'+value+'!\n'); + res.end(' key:' +key +' value:'+value+'!\n'); } +function relationBboxHandler(req, res, key, value, left, bottom, right, top) { -function helloWorld(req, res) { - helloSomeone(req, res, 'World'); } -myRoutes = clutch.route404([['GET /hello/(\\w+)(\\[bbox=(\\d,\\d,\\d,\\d)\\])*\\[(\\w+)=(\\w+)\\]$', helloSomeone], - ['GET /hello/$', helloWorld]]); +myRoutes = clutch.route404([ + //['GET /api/(\\w+)(\\[bbox=(\\d,\\d,\\d,\\d)\\])*\\[(\\w+)=(\\w+)\\]$', helloSomeone], + ['GET /api/node\\[(\\w+)=(\\w+)\\]$',nodeWorldHandler], + ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+(\\.\\d+)?),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], + ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+\\.\\d+),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], + ['GET /api/way\\[(\\w+)=(\\w+)\\]$',wayWorldHandler], + ['GET /api/way\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d),(\\d),(\\d),(\\d)\\]$',wayBboxHandler], + ['GET /api/relation\\[(\\w+)=(\\w+)\\]$',relationWorldHandler], + ['GET /api/relation\\[(\\w+)=(\\w+)\\](\\[bbox=(\\d),(\\d),(\\d),(\\d)\\])$',relationBboxHandler], + ]); var http = require('http'); -http.createServer(myRoutes).listen(3000, '127.0.0.1'); +http.createServer(myRoutes).listen(8080, 'localhost'); |