Created
September 14, 2010 02:58
-
-
Save gsmcwhirter/578449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
sys = require('sys'), | |
responseText = ''; | |
var client = http.createClient(7080,'127.0.0.1'); | |
var request = client.request("GET","/api/users.json",{"Accept": "*/*","Host":"127.0.0.1"}); | |
request.on("response", function (r){ | |
r.setEncoding('utf8'); | |
sys.debug(r.statusCode); | |
r.on("data", function (c){ | |
responseText += c; | |
}); | |
r.on("end", function(){ | |
sys.puts(responseText); | |
}); | |
}); | |
request.end(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node.js:63 | |
throw e; | |
^ | |
Error: Parse Error | |
at Client.ondata (http:901:22) | |
at IOWatcher.callback (net:494:29) | |
at node.js:769:9 | |
//Node version checked out from github today (0.2.1+) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//server listening via app.listen(7080); | |
var couchdb = require('../couchdb'), | |
base = require('../base'), | |
us = require('underscore'); | |
//handler goes through a connect/express router like this | |
//app.get("/api/users.:format", userList); | |
function userList(req, res, next){ | |
var config = req.app.set('sys config'); | |
var url = config.couchdb_server+"/"+config.couchdb+"/_design/player/_view/handles/"; | |
var creq = new couchdb.Request("GET", url, function (response){ | |
if(!response.error) | |
{ | |
if (req.params.format == "json") | |
{ | |
res.writeHead(200, {"Content-type": "application/json"}); | |
res.end(JSON.stringify(us._.map(response.rows, function (item){return item.key[1].toLowerCase();})), 'utf8'); | |
} | |
else | |
{ | |
next(); | |
} | |
} | |
else | |
{ | |
next(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment