aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs/no1.js
diff options
context:
space:
mode:
authorPhilipp Borgers <borgers@mi.fu-berlin.de>2011-01-13 01:49:48 +0100
committerPhilipp Borgers <borgers@mi.fu-berlin.de>2011-01-13 01:49:48 +0100
commitf9c8e0df93c69ca40e404dbc658f89c6cfbeb7fa (patch)
treedcd5022ad83e47cb066bdfa199b989bfde23c765 /src/nodejs/no1.js
parent97baff32fd82630497d761f36b5e34466f8ecbc1 (diff)
downloadosm-xapi-f9c8e0df93c69ca40e404dbc658f89c6cfbeb7fa.tar.gz
osm-xapi-f9c8e0df93c69ca40e404dbc658f89c6cfbeb7fa.tar.xz
osm-xapi-f9c8e0df93c69ca40e404dbc658f89c6cfbeb7fa.zip
fuck you regex... database request possible. we have to learn regex!!!
Diffstat (limited to 'src/nodejs/no1.js')
-rw-r--r--src/nodejs/no1.js82
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');