app.js
This file
Path
examples/chat/app.js
81 lines · 1.8 KiB · JavaScript
Last changed by
Merge branch 'node-0.1.30'visionmediabefore adoptionf7d7c4a
History of this fileTake it
Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 1–6why, one step back12require.paths.unshift('lib')3require('express')4require('express/plugins')56configure(function(){Session options in chat sample appvisionmediabefore adoption20cf8f8
lines 7–8why, one step back7 var fiveMinutes = 300000,8 oneMinute = 60000Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 9–10why, one step back9 use(MethodOverride)10 use(ContentLength)CommonLogger back in chat appvisionmediabefore adoption8309537
line 11why, one step back11 use(CommonLogger)We cannot use(Cookie) within Session.init()visionmediabefore adoption7cdbca0
line 12why, one step back12 use(Cookie)Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
line 13why, one step back13 use(Cache, { lifetime: fiveMinutes, reapInterval: oneMinute })Session options in chat sample appvisionmediabefore adoption20cf8f8
line 14why, one step back14 use(Session, { lifetime: fiveMinutes, reapInterval: oneMinute })Mergevisionmediabefore adoptioncec6770
line 15why, one step back15 set('root', __dirname)Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 16–17why, one step back16})17Mergevisionmediabefore adoptioncec6770
lines 18–19why, one step back18var messages = [],19 utils = require('express/utils')Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 20–27why, one step back20 21get('/', function(){22 this.redirect('/chat')23})2425get('/chat', function(){26 this.render('chat.haml.html', {27 locals: {fix layout locals. Closes #163visionmediabefore adoption825e8b6
line 28why, one step back28 title: 'Chat',More session workvisionmediabefore adoption047499d
line 29why, one step back29 messages: messages,Added online user count to chat appvisionmediabefore adoption944f99a
lines 30–31why, one step back30 name: this.session.name,31 usersOnline: Session.store.length()Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 32–36why, one step back32 }33 })34})3536post('/chat', function(){More session workvisionmediabefore adoption047499d
line 37why, one step back37 this.session.name = this.param('name')Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
line 38why, one step back38 messagesMergevisionmediabefore adoptioncec6770
line 39why, one step back39 .push(utils.escape(this.param('name')) + ': ' + utils.escape(this.param('message'))Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 40–57why, one step back40 .replace(/(http:\/\/[^\s]+)/g, '<a href="$1" target="express-chat">$1</a>')41 .replace(/:\)/g, '<img src="http://icons3.iconfinder.netdna-cdn.com/data/icons/ledicons/emoticon_smile.png">'))42 this.halt(200)43})4445get('/chat/messages', function(){46 var self = this,47 previousLength = messages.length,48 timer = setInterval(function(){49 if (messages.length > previousLength)50 self.contentType('json'),51 previousLength = messages.length,52 self.halt(200, JSON.encode(messages)),53 clearInterval(timer)54 }, 100)55})5657get('/public/*', function(file){Mergevisionmediabefore adoptioncec6770
line 58why, one step back58 this.sendfile(__dirname + '/public/' + file)Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 59–74why, one step back59})6061get('/*.css', function(file){62 this.render(file + '.sass.css', { layout: false })63})6465get('/error/view', function(){66 this.render('does.not.exist')67})6869get('/error', function(){70 throw new Error('oh noes!')71})7273get('/simple', function(){74 return 'Hello :)'Session docsvisionmediabefore adoption9d5a6f9
lines 75–78why, one step back75})7677get('/favicon.ico', function(){78 this.halt()Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
lines 79–81why, one step back79})8081run()