|
|
JS3DB stores and retrieves Javascript objects as JSON using Amazon S3. One could use this to create an entire application in HTML/Javascript, with Amazon S3 as the datastore.
Overview
Browser-based applications have come a long way over the last few years. Rich desktop-like applications can live inside a single HTML file, fueled by Javascript and Ajax.
However these applications lack an inherent method for storing data. Javascript's same-origin policy prevents an application on one domain from saving data to another domain.
JS3DB gets around these limitations by using Amazon S3 to store all files and data. Amazon S3 provides a simple web services interface that can be used to store and retrieve data.
Installation
- Grab the latest code from the downloads page.
- Unpack and copy the code to your Amazon S3 bucket. I recommend S3Fox to easily create buckets and transfer files to S3.
- Edit the ACL for each file to allow everyone read access.
- Visit the test page at http://s3.amazonaws.com/your-bucket-name/test.html
Example
You can test out JS3DB here: http://s3.amazonaws.com/js3db/test.html
How It Works
Here's a quick overview of how JS3DB works:
- Data is stored an retrieved as JSON objects.
- All files are hosted on http://s3.amazonaws.com/your-bucket-name/ (circumventing the same-origin policy)
- Uses an XmlHttpRequest over Amazon's S3 REST interface to write javascript files to the server
Using this system, a developer could create an application without worry about building an maintaining a server component.
The JS3DB library has a few layers:
- JS3DB - the core library for reading/writing files
- JS3DB.Auth - stores S3 authentication credentials
- JS3DB.Auth.Cookie - persists S3 auth credentials to a browser cookie
- JS3DB.Auth.DOM - shows a login page to users to collect S3 credentials before making a request.
Really all you need to take advantage of storage is JS3DB. The JS3DB.Auth classes offer an easy way to integrate with applications.
A note about security: This implementation of JS3DB has the option of storing your S3 credentials in a cookie. The cookie is not encrypted and is not secure. Its best to use this option for testing purposes only. I'm not sure of a better way to persist S3 credentials on the client side; any suggestions are welcome.
Known Issues
- Currently works only with urls in the format http://s3.amazonaws.com/your-bucket-name/ It'll eventually support urls in the format http://your-bucket-name.s3.amazon.com/ This url format is desirable because it offers a unique domain name, which is more secure.
Shout Outs
The JS3DB library is built upon the following javascript libraries:
- S3Ajax - Ajax library for Amazon S3
- sha1.js - SHA1 for Javascript
- JSON - JSON serializer for Javascript
Contact
Send any questions and comments to monsur at gmail.
