Skip to content

Commit

Permalink
added an example
Browse files Browse the repository at this point in the history
  • Loading branch information
CrypticSwarm committed May 6, 2011
1 parent cfeb2f3 commit 50441fd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
33 changes: 33 additions & 0 deletions example/datamonkey.js
@@ -0,0 +1,33 @@
var express = require('express')
, app = express.createServer()
, dataLayer = require('../data-cache')()

app.configure(function(){
app.use(express.logger())
app.set('view engine', 'jade')
})

app.get('/', dataLayer.connectDataTemplate('index/all', 'index'))
app.get('/:cryptic', dataLayer.connectDataTemplate(':cryptic/all', 'index')) // the params in the external url match an internal url they get passed through


dataLayer.compositeRoute(':chaos/all', // Again here the params get passed through if they match.
{ 'datamonkey': 'name'
, 'cryptic/:chaos': 'message' // However the names are independent of what we called them in the other section
})

dataLayer.addRoute('datamonkey', function(req, cb) {
console.log('Fetching: ', req.url)
setTimeout(function() {
cb(null, "The Message")
}, 100)
}, 3000)

dataLayer.addRoute('cryptic/:swarm', function(req, cb) {
console.log('Fetching: ', req.url)
setTimeout(function() {
cb(null, "This is the a parametrized response " + req.params.swarm)
}, 1000)
}, 10000)

app.listen(3000)
2 changes: 2 additions & 0 deletions example/views/index.jade
@@ -0,0 +1,2 @@
h2 #{name}
h3 #{message}
8 changes: 8 additions & 0 deletions example/views/layout.jade
@@ -0,0 +1,8 @@
!!!5
html
head
title #{name}
body
h1 Data Layer!
!=body

0 comments on commit 50441fd

Please sign in to comment.