Instructions for setting up a Hacker News button server
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I'd like complete instructions for setting up a HackerNews button server on Google AppEngine. hnbutton.appspot.com works fine most of the time, but unfortunately it hits its traffic quota on a regular basis.

I have no experience with Go or AppEngine, so please provide very detailed step-by-step instructions for setting up the server. Any blogger (technical or not) should be able to host their own HN button server with your instructions.

I'll also tip $5 if you provide a patch that restricts the service to buttons hosted at a specific URL.

Let me know if you have any questions before starting. Thanks!

Edit

My post may not have been clear enough. The github page I linked to above shows how to add the HN button to a website, which I know how to do and already have in place. There's actually a backend server serving the button, which isn't immediately clear by looking at the embed code. If you look at the JS embed code on the Github page, it loads this file: http://hnbutton.appspot.com/static/hn.js. Looking at hn.js, you'll see that the code makes a call to the server at hnbutton.appspot.com with some URL parameters. The code for the server is in the github repo as well (it's the .go file). I want instructions to set up my own back-end button server running that .go file. Thanks.

README file in HN button repo have the step by step to add the button to any page. You want instructions for setting up your application, not only for Hacker News button.
iurisilvio 6 years ago
Sorry, my question was not very clear, I'll update it now.
bevan 6 years ago
awarded to weslly

Crowdsource coding tasks.

1 Solution


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:

}
Thanks for the great solution. Setting up the server worked exactly as you describe above. Will verify the "extra" bit tomorrow, looks promising though.
bevan 6 years ago
I was reading the bountify blog and I saw an error with the button, I've checked the page source code and you aren't using the domain at the "data-url" attribute. It will fix the problem :)
weslly 6 years ago
Thanks for the tip! Just pushed a fix.
bevan 6 years ago