Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Forked from micahasmith/server.js
Created May 13, 2012 18:52
Show Gist options
  • Save grantmichaels/2689724 to your computer and use it in GitHub Desktop.
Save grantmichaels/2689724 to your computer and use it in GitHub Desktop.
node.js google reverse geocode proxy
var http = require('http'),
q = require('querystring')
http.createServer(function (req, res) {
//create the geo long/lat path
var url=["/maps/geo?q="
,q.parse(req.url)["long"]
,","
,q.parse(req.url)["lat"]
,"&output=json&sensor=false"].join(""),
//create the options to pass into the get request
options={host:"maps.google.com"
,path:url};
//a little lightweight logging to watch requests
console.log("url:",options.host+options.path);
console.log("requrl:",req.url);
//make the request server side
http.get(options,function(response){
//console.log("hi",response);
res.writeHead(200, {'Content-Type': 'text/plain'});
var pageData = "";
response.setEncoding('utf8');
//stream the data into the response
response.on('data', function (chunk) {
pageData += chunk;
});
//write the data at the end
response.on('end', function(){
res.write(pageData);
res.end();
});
});
}).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment