app.js
This file
Path
examples/app.js
54 lines · 1.0 KiB · JavaScript
Last changed by
Throwing error when view fails [#114]visionmediabefore adoptionca4b61e
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
require.paths.unshift('lib')require('express')require('express/plugins')
configure(function(){ use(MethodOverride) use(ContentLength) use(CommonLogger) set('root', dirname(__filename)) enable('cache views')})
var messages = [], StaticFile = require('express/static').File get('/', function(){ this.redirect('/chat')})
get('/chat', function(){ this.render('chat.haml.htmls', { locals: { messages: messages } })})
post('/chat', function(){ messages.push(escape(this.param('message'))) this.halt(200)})
get('/chat/messages', function(){ var self = this, previousLength = messages.length, timer = setInterval(function(){ if (messages.length > previousLength) self.contentType('json'), previousLength = messages.length, self.halt(200, JSON.encode(messages)), clearInterval(timer) }, 100)})
get('/public/*', function(file){ this.sendfile(dirname(__filename) + '/public/' + file)})
get('/error', function(){ throw new Error('oh noes!')})
run()