Skip to content

Instantly share code, notes, and snippets.

@lkptrzk
Created February 22, 2014 03:17
Show Gist options
  • Select an option

  • Save lkptrzk/9148139 to your computer and use it in GitHub Desktop.

Select an option

Save lkptrzk/9148139 to your computer and use it in GitHub Desktop.
Random reddits page
function serveReddit (req, res) {
function recurse(i, res) {
if (i <= 0)
res.end('</ul></div>')
request({
uri: 'http://www.reddit.com/r/random',
followRedirect: false
}, function (err, response, body) {
var location = response.headers.location
res.write(
'<li><a href="' +
location +
'">' +
url.parse(location).pathname +
'</a></li>'
)
recurse(i - 1, res)
})
}
res.writeHead(200, {'Content-Type': 'text/html'})
res.write(
'<!DOCTYPE>' +
'<title>randoreddit</title>' +
// '<script src="/content/centerize.js"></script>' +
'<link rel="stylesheet" href="/content/reddit.css">' +
'<body>' +
'<div>' +
'<h1>randoreddit</h1>' +
'<ul>'
)
recurse(25, res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment