Google Drive allows a very convenient and free way host web pages. You simply share the folder to the public and anyone can go to http://googledrive.com/host/<folder id> with their browser and see your web site. Publishing a page or any file is just a matter of dropping it into the drive folder. However, Drive currently doesn't support custom domains so if you have your own domain (e.g. example.com) you can't have http://www.example.com be served from Drive.
There is a site, http://gweb.io, that allows you to do this for about $10/year, but I've never used them or know much about them. Instead, this article will describe one way to roll your own using Google App Engine (GAE) and if your site only have moderate traffic you should be able to stay within its free quota. Note: this was a quick hack I did and not meant to be a high performance web site. Don't be running your own Google with this! :-)
The basic idea is very simple. GAE allows you to have custom domains so you create an app on it and it can map to your domain (e.g. http://www.example.com). What the app will do is take the URL, translate it to the googledrive.com URL and fetch the page for you and return it through app engine.
http://googledrive.com/host/page1.htmlWith the mapping, use GAE's FetchURL service to grab the file and pass it back to the caller. That's it.
Follow the GAE tutorial on setting up a basic helloworld app (such as this one for Go). Instead of hello.go, I have file called "fetch.go" and instead of "package hello" it is "package fetch". For the content of fetch.go:
Now give it a try on your local server to make sure it works and then upload your project. If everything is working well, you can them map this app to your domain. That's it!
Now, this is not very optimized and only really recommended for small sites. For example, this will fetch from googledrive on every request and the browser might not be able to cache it. For the former, it would be easy to insert memcache to keep a cached version on the server side. For the latter, we'd want to stick in some headers to help browsers cache the file unless the file is updated very frequently.
Anyway, with GAE's generous free quota, this might work well for many small sites out there to serve some examples web sites or landing pages.
One question we might ask ourselves is that why use Drive at all if you're using GAE already? For me it was mainly convenience of being able to just drop the file into a drive folder and 'cause I just wanted to write some Go code on GAE.
This comment has been removed by a blog administrator.ReplyDelete
Well, why not just use GAE for hosting the files?ReplyDelete
Mainly ease of use. Google Drive already have clients for Windows and OSX so one can just drag-and-drop files to it and it has all the syncing mechanism built-in. I can just edit edit files on my machine, save and it will appear on the site without having to upload the file and set up GAE blob store, etc.Delete
This is NOT working. Google's tutorials are a piece of shit and super confusing. The platform is constantly changing. I just want to get this uploaded like yesterday!!!ReplyDelete
Please help for the life of me.
Google shut down this feature this year so unfortunately this post is no longer relevant.Delete