Wednesday, January 28, 2015

Geek: the impossible just takes a little longer...

Geek: the impossible just takes a little longer...  The reason I started coding again is because I'm working on bringing up my new blog (SlightlyLoony).  It will probably be a few months before I actually start posting there, as I have quite a bit of coding to do before it will work the way I want it to.  Partly that's because I'm hosting it on Ghost, which is a brand-new and not fully baked yet blogging platform.  Mostly, though, it's because I want some features that the Ghost platform doesn't support, and likely never will.

One of those features I wanted is the ability to upload some data to the blog periodically, and then have that data available to people reading the blog.  For instance, I'd like to have the weather forecast for the next few days show up.  I can “scrape” that sort of data from other web sites, then package it up for display on my blog – but to do that, I need to upload that data to the blog server somehow.  Many blogging platforms provide an API for that sort of thing, but Ghost does not.  I spent quite a bit of time on the Ghost forums, researching the issue and asking questions about it.  The conclusion from expert Ghost developers: it can't be done.

This morning I came up with a way to do it, and I whipped up a prototype and tested it – it works!  Best of all, it's easy as can be.  Here's how it works:
  • I created a special “bucket” on Amazon's AWS S3 storage service.  This bucket has the name “”.
  • I created a DNS record (a CNAME record) that aliases “” to the S3 storage URL.
  • I wrote a program that uploads the data of interest to a particular set of files within the S3 bucket.
  • In my client side code (running in the blog reader's browser), whenever I want to access some of that data, I use the URL “[file name]” to get it.  The browser thinks it's on the same host, because “” is a subdomain of “”, where the browser loaded the page from.  No cross-site scripting rules are violated by this.

No comments:

Post a Comment