Enabling POST request for Ghost Blog

I have a problem. I am creating a Facebook App for my blog, which actually resides as 🌍 My Blog in Facebook. The sad part is that, Facebook Apps need two things for an App to work:

  • Should have 🔒 https://.
  • Should accept HTTP POST request.

Unfortunately, the Ghost blog doesn't allow this. When you try sending a HTTP POST request to your Ghost installation, you encounter something like this:

Page not found.

This is bad, as when your website is live, and when it is shown this way to the users, it kinda sucks. 😡 So, the best way is to hack into the router of this open source gem and add some nice handlers in the 🗈 frontend.js, so your site doesn't break when Facebook requests the App website through a HTTP POST method:

// Handle the POST requests and send a temporary redirect to the main page.
router.post('/', function (req, res) {  
  utils.redirect301(res, '/');
});

Note: Since I have installed my blog in the root, I use / after the res. If you have installed in a sub-directory, say /blog/ or something, just use the path from the domain.

You need to add this before the export function, 🗈 which would be like:

return router;  

Now, if the Facebook App sends a HTTP POST request, it shows your awesome blog. Hope this was useful to someone, who is using their Ghost blog installation for Facebook Apps. 😎