app.js
This file
Path
examples/app.js
55 lines · 971 bytes · JavaScript
Last changed by
CommonLogger showing "/" as rootvisionmediabefore adoption2b02305
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
require.paths.unshift('lib')require('express')require('express/plugins')
configure(function(){ use(CommonLogger) use(MethodOverride) use(ContentLength) set('root', dirname(__filename)) enable('helpful 404') enable('show exceptions') enable('cache views')})
var messages = []
get('/', function(){ redirect('/chat')})
get('/chat', function(){ render('chat.haml.html', { locals: { messages: messages } })})
post('/chat', function(){ messages.push(param('message')) halt(200)})
get('/chat/messages', function(){ contentType('json') return JSON.encode(messages)})
get('/public/:file', function(file){ var path = dirname(__filename) + '/public/' + file require('path').exists(path, function(exists){ if (!exists) halt() require('posix').cat(path).addCallback(function(content){ contentType(path) halt(200, content) }) })})
get('/error', function(){ throw new Error('oh noes!')})
run()