New here? Learn about Bountify and follow @bountify to get notified of new bounties! x
← All posts

Host your own Hacker News button server

Posted by bevan on Nov 20

Use the HN button on your blog? Then you've probably noticed that the button server is very frequently over its quota.

I posted a bounty last week asking for instructions on setting up my own HN button server on Google Appengine. The instructions I received were very straightforward and I had my server up in no time.

The server only took a few minutes to set up and I had no prior experience with Go or AppEngine. Plus, setting up the server is free.

Furthermore, you can set the button server up such that nobody else can piggyback on it (the solution includes a fix that restricts requests to buttons hosted at a specific domain).

For the uninitiated, the HN button is served by a backend server. To use the solution below, you'll have to put the static/hn.js file (from here) on your webserver, and change the button embed code to point to it.

To host your own HN button server, follow the instructions below (reprinted from this bounty):

Steps

Bonus - Restrict the service to a specific domain

Server Side

Open hnbutton.go and find this line (as of the time of writing, line 64):

_, err := url.Parse(req_url[0])

Change it to:

checkurl, err := url.Parse(req_url[0])
if checkurl.Host != "yourdomain.com" {
    panic("Invalid URL")
}

Client Side

Add this to the first line of static/hn.js:

if (window.location.hostname == 'yourdomain.com') {

and this to the end of the file:

}
← All posts
Painlessly Crowdsource Small Coding Tasks with Bountify
  1. Post a bounty
  2. Verify solutions
  3. Pick a winner
About | FAQ | Sign up