FW/1 with Coldspring and CouchDB »

0

Tags: Railo, CouchDB, Projects, FW/1, Coldfusion

I have recently built a web application that i am currently using as my 'playground' to learn and test new things. Having experimented with a few frameworks (Coldbox / Fusebox), i thought it time to look at another. This time FW/1, from Sean Corfield, was the choice.

The initial application was built using the excellent auto wiring of the MVC of FW/1 and using MySQL. However, close to the end of this i began reading up on CouchDB and the NoSQL approach. Wanting to pick this up i ended up modifying the existing application to use CouchDB as an alternative data storage changing the Application.cfc to choose between the two.

The application, a basic url shortener, was written on Railo 3.1.2.019 as i wanted to try writing fully scripted components, and works fine under Adobe ColdFusion 9.

Requirements :

 

Once all the above have been installed, unzip the contents of demo application into the web route. (Download at bottom of post). Depending on the type of database that is required that comes with the download.. the instructions vary :

MySQL - create a database and run the .sql included within the download and setup the datasource with the Railo / CF admin
CouchDB - create a database in the couchDB admin, normally located at localhost:5984 after installation

Before running the application, setup the Application.cfc with the relevant information with the Config. These values need to be adjusted and are injected into the objects by Coldspring using the Variable Syntax in the Coldspring.xml.cfm.

Application.cfc

this.default = structNew();
this.default.url = '__APPLICATION-URL__';
this.default.dbhost = '__COUCHDB-HOST__';
this.default.port = '__COUCHDB-PORT__';
this.default.dsn = '__MYSQL-DSN__';
this.default.dbtype = '__DBTYPE__';
this.default.db = '__COUCHDB-DATABASE__';

Once all the above has been setup then we are pretty much good to go. Navigate to the url where the application has been installed, and fingers crossed all should be working. To test the application a url is needed and this will be shortened for you, if valid.

Note : to ensure that the urls are kept as short as possible, some url rewriting is required whether with web.config or .htaccess. I use following .htaccess to ensure that a url like http://webapp.com/gHjEs does not return an error but redirects to the correct location.

# ignore following directories
RewriteRule ^(assets|views|controllers|layouts|services)(/.*)?$ - [NC,L]

# attempt redirect of the short url
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} !index.cfm
RewriteRule ^(.*)$ index.cfm?go=main.redirect&s=$1 [L]

 

Extending the application

In attempt to follow true OOP the code has been written in a way so that any extra database types can be added, whether it is XML, Sql Server etc. Each new gateway.cfc that handles database interaction must reside into a directory within the /services folder. The Gateway.cfc must implement the interface IGateway.cfc and extend the Gateway.cfc in the service directory. All code that requires that specific database type can be included in the newly create component. In the parent cfc (that is being extended) are 3 functions that start the shortening process and generate the unique keys. Please refer to this to see how it is implemented.

Please feel free to comment on the application or suggestions that may improve it, or if you would like help getting it to work then please leave a comment.

 

0 responses to “FW/1 with Coldspring and CouchDB”

leave a reply

Leave this field empty: