app.js
This file
Path
examples/chat/app.js
69 lines · 1.4 KiB · JavaScript
Last changed by
Removed unnecessary require in chat appvisionmediabefore adoption9d0d6e4
History of this fileTake it
Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 1–14why, one step back12require.paths.unshift('lib')3require('express')4require('express/plugins')56configure(function(){7 use(MethodOverride)8 use(ContentLength)9 use(CommonLogger)10 set('root', dirname(__filename))11 enable('cache static files')12 //enable('cache view contents')13})14Removed unnecessary require in chat appvisionmediabefore adoption9d0d6e4
line 15why, one step back15var messages = []Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 16–69why, one step back16 17get('/', function(){18 this.redirect('/chat')19})2021get('/chat', function(){22 this.render('chat.haml.html', {23 locals: {24 messages: messages25 }26 })27})2829post('/chat', function(){30 messages31 .push(escape(this.param('message'))32 .replace(/(http:\/\/[^\s]+)/g, '<a href="$1" target="express-chat">$1</a>')33 .replace(/:\)/g, '<img src="http://icons3.iconfinder.netdna-cdn.com/data/icons/ledicons/emoticon_smile.png">'))34 this.halt(200)35})3637get('/chat/messages', function(){38 var self = this,39 previousLength = messages.length,40 timer = setInterval(function(){41 if (messages.length > previousLength)42 self.contentType('json'),43 previousLength = messages.length,44 self.halt(200, JSON.encode(messages)),45 clearInterval(timer)46 }, 100)47})4849get('/public/*', function(file){50 this.sendfile(dirname(__filename) + '/public/' + file)51})5253get('/*.css', function(file){54 this.render(file + '.sass.css', { layout: false })55})5657get('/error/view', function(){58 this.render('does.not.exist')59})6061get('/error', function(){62 throw new Error('oh noes!')63})6465get('/simple', function(){66 return 'Hello :)'67})6869run()