Skip to content

Instantly share code, notes, and snippets.

@MetaThis
Created August 25, 2011 22:03
Show Gist options
  • Save MetaThis/1172108 to your computer and use it in GitHub Desktop.
Save MetaThis/1172108 to your computer and use it in GitHub Desktop.
Simple example of a Node.js proxy to CouchDB GET requests
var http = require('http'),
request = require('request'), // request module from https://github.com/mikeal/request
url = require('url');
http.createServer(function (req, res) {
var href = url.parse(req.url,true).href;
request('http://127.0.0.1:5984' + href).pipe(res);
}).listen(1337);
// now try something like http://127.0.0.1:1337/your_db_name/_all_docs/?limit=10
@mikeal
Copy link

mikeal commented Aug 25, 2011

@mvolkmann yeah, this is too simple, let's add a compiler to it :P

@isaacs
Copy link

isaacs commented Aug 25, 2011

TOO VERBOSE AND LONG!!

http.createServer(function (req, res) {
  request(url.resolve('http://127.0.0.1:5984', req.url)).pipe(res);
}).listen(1337);

@mikeal
Copy link

mikeal commented Aug 25, 2011

in 0.5.x you can do

http.createServer(function (req, res) {
  req.pipe(request(url.resolve('http://127.0.0.1:5984', req.url))).pipe(res)
}).listen(1337)

@mvolkmann
Copy link

I love JavaScript, but after using CoffeeScript for the past two weeks, JavaScript just looks so noisy. I don't have to worry about compiling though. I have "coffee -cwo ..." running so all the files get compiled in the background. BTW mikeal, thanks so much for everything you've done for the Node community! I use your modules often!

@MetaThis
Copy link
Author

@isaacs @mikeal Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment