Skip to content

Instantly share code, notes, and snippets.

@notlion
Created September 18, 2012 00:07
Show Gist options
  • Save notlion/3740535 to your computer and use it in GitHub Desktop.
Save notlion/3740535 to your computer and use it in GitHub Desktop.
Derby Test
var derby = require('derby')
, app = derby.createApp(module)
app.get('/', function(page, model, params, next) {
model.subscribe("result", function(err, all) {
page.render()
})
})
app.ready(function(model) {
})
<Title:>
Derby Test!
<Body:>
<input type="text" name="a" value="{a}" /> + <input type="text" name="b" value="{b}" /> = {result}
var http = require('http')
, path = require('path')
, express = require('express')
, gzippo = require('gzippo')
, derby = require('derby')
, app = require('../app')
, serverError = require('./serverError')
var expressApp = express()
, server = module.exports = http.createServer(expressApp)
derby.use(derby.logPlugin)
var store = derby.createStore({ listen: server })
var ONE_YEAR = 1000 * 60 * 60 * 24 * 365
, root = path.dirname(path.dirname(__dirname))
, publicPath = path.join(root, 'public')
store.afterDb("set", "*", function(txn, doc, previousDoc, done) {
if(txn[1].charAt(0) != '#') {
store.set("result", "hello", function(){})
}
done()
})
expressApp
.use(express.favicon())
.use(gzippo.staticGzip(publicPath, { maxAge: ONE_YEAR }))
.use(express.compress())
.use(store.modelMiddleware())
.use(app.router())
.use(expressApp.router)
.use(serverError(root))
expressApp.all('*', function(req) {
throw '404: ' + req.url
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment