Skip to content
Myr

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 file

Take it

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 1–6why, one step back
1
2require.paths.unshift('lib')3require('express')4require('express/plugins')56configure(function(){

Session options in chat sample appvisionmediabefore adoption20cf8f8

lines 7–8why, one step back
7 var fiveMinutes = 300000,
8 oneMinute = 60000

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 9–10why, one step back
9 use(MethodOverride)
10 use(ContentLength)

CommonLogger back in chat appvisionmediabefore adoption8309537

line 11why, one step back
11 use(CommonLogger)

We cannot use(Cookie) within Session.init()visionmediabefore adoption7cdbca0

line 12why, one step back
12 use(Cookie)

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

line 13why, one step back
13 use(Cache, { lifetime: fiveMinutes, reapInterval: oneMinute })

Session options in chat sample appvisionmediabefore adoption20cf8f8

line 14why, one step back
14 use(Session, { lifetime: fiveMinutes, reapInterval: oneMinute })

Mergevisionmediabefore adoptioncec6770

line 15why, one step back
15 set('root', __dirname)

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 16–17why, one step back
16})
17

Mergevisionmediabefore adoptioncec6770

lines 18–19why, one step back
18var messages = [],
19 utils = require('express/utils')

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 20–27why, one step back
20
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 back
28 title: 'Chat',

More session workvisionmediabefore adoption047499d

line 29why, one step back
29 messages: messages,

Added online user count to chat appvisionmediabefore adoption944f99a

lines 30–31why, one step back
30 name: this.session.name,
31 usersOnline: Session.store.length()

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 32–36why, one step back
32 }
33 })34})3536post('/chat', function(){

More session workvisionmediabefore adoption047499d

line 37why, one step back
37 this.session.name = this.param('name')

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

line 38why, one step back
38 messages

Mergevisionmediabefore adoptioncec6770

line 39why, one step back
39 .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 back
40 .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 back
58 this.sendfile(__dirname + '/public/' + file)

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 59–74why, one step back
59})
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 back
75})
7677get('/favicon.ico', function(){78 this.halt()

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 79–81why, one step back
79})
8081run()