-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c806d1a
Showing
14 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
io = require('socket.io') | ||
express = require('express') | ||
routes = require('./routes') | ||
sockets = require('./sockets') | ||
|
||
app = module.exports = express.createServer() | ||
|
||
|
||
app.configure () -> | ||
app.set('views', __dirname + '/views') | ||
app.set('view engine', 'hbs') | ||
app.use(express.bodyParser()) | ||
app.use(express.methodOverride()) | ||
app.use(app.router) | ||
app.use(express.static(__dirname + '/public')) | ||
|
||
app.configure 'development', () -> | ||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })) | ||
|
||
|
||
app.configure 'production', () -> | ||
app.use(express.errorHandler()) | ||
|
||
app.get('/', routes.index) | ||
|
||
app.listen 3000, () -> | ||
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env) | ||
|
||
sio = io.listen(app) | ||
sio.of('/'+command).on('connection', sockets[command].connection) for command in sockets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "base-app" | ||
, "version": "0.0.1" | ||
, "private": true | ||
, "dependencies": { | ||
"express": "2.5.8" | ||
, "coffee-script": "1.3.3" | ||
, "hbs": "1.0.2" | ||
, "socket.io": "0.9.6" | ||
, "supervisor": "0.3.1" | ||
} | ||
, "scripts" : { | ||
"start": "./node_modules/.bin/supervisor -e \"node|js|coffee\" run.js" | ||
, "test": "./node_modules/.bin/mocha $(find test -name \"*_test.coffee\")" | ||
} | ||
, "devDependencies": { | ||
"should": "0.6.3" | ||
, "mocha": "1.0.3" | ||
, "sinon": "1.3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exports.index = (req, res) -> | ||
res.render('index', { title: 'Express' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('coffee-script'); | ||
require('./app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require("fs").readdirSync("./sockets").forEach (file) -> | ||
module.exports[file.split('.')[0]] = require("./sockets/" + file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
connection : (socket) -> | ||
console.log "index socket connected" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--compilers coffee:coffee-script | ||
--reporter dot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
routes = require ('../../routes') | ||
should = require('should') | ||
|
||
describe 'Routes', -> | ||
describe 'Index', -> | ||
it 'should respond to default route', (done)-> | ||
routes.index {}, { | ||
render: (viewName,options) -> | ||
viewName.should.equal("index") | ||
options.title.should.equal("Express") | ||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sockets = require '../../sockets' | ||
should = require('should') | ||
|
||
describe "Socket", -> | ||
describe "Index", -> | ||
it "should have an index channel", -> | ||
should.exist sockets.index | ||
|
||
it "should have a connection callback for index", -> | ||
should.exist sockets.index.connection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
/** | ||
* visionmedia <3 | ||
* Module dependencies. | ||
*/ | ||
|
||
var EventEmitter = require('events').EventEmitter | ||
, methods = require('express').router.methods | ||
, http = require('http'); | ||
|
||
module.exports = request; | ||
|
||
function request(app) { | ||
return new Request(app); | ||
} | ||
|
||
function Request(app) { | ||
var self = this; | ||
this.data = []; | ||
this.header = {}; | ||
this.app = app; | ||
if (!this.server) { | ||
this.server = http.Server(app); | ||
this.server.listen(0, function(){ | ||
self.addr = self.server.address(); | ||
self.listening = true; | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Inherit from ventEmitter.prototype | ||
*/ | ||
|
||
Request.prototype.__proto__ = EventEmitter.prototype; | ||
|
||
methods.forEach(function(method){ | ||
Request.prototype[method] = function(path){ | ||
return this.request(method, path); | ||
}; | ||
}); | ||
|
||
Request.prototype.set = function(field, val){ | ||
this.header[field] = val; | ||
return this; | ||
}; | ||
|
||
Request.prototype.write = function(data){ | ||
this.data.push(data); | ||
return this; | ||
}; | ||
|
||
Request.prototype.request = function(method, path){ | ||
this.method = method; | ||
this.path = path; | ||
return this; | ||
}; | ||
|
||
Request.prototype.expect = function(body, fn){ | ||
this.end(function(res){ | ||
if ('number' == typeof body) { | ||
res.statusCode.should.equal(body); | ||
} else if (body instanceof RegExp) { | ||
res.body.should.match(body); | ||
} else { | ||
res.body.should.equal(body); | ||
} | ||
fn(); | ||
}); | ||
}; | ||
|
||
Request.prototype.end = function(fn){ | ||
var self = this; | ||
|
||
if (this.listening) { | ||
var req = http.request({ | ||
method: this.method | ||
, port: this.addr.port | ||
, host: this.addr.address | ||
, path: this.path | ||
, headers: this.header | ||
}); | ||
|
||
this.data.forEach(function(chunk){ | ||
req.write(chunk); | ||
}); | ||
|
||
req.on('response', function(res){ | ||
var buf = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function(chunk){ buf += chunk }); | ||
res.on('end', function(){ | ||
res.body = buf; | ||
fn(res); | ||
}); | ||
}); | ||
|
||
req.end(); | ||
} else { | ||
this.server.on('listening', function(){ | ||
self.end(fn); | ||
}); | ||
} | ||
|
||
return this; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>{{title}}</h1> | ||
<p>Welcome to {{title}}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{title}}</title> | ||
<link rel="stylesheet" href="/stylesheets/style.css" /> | ||
</head> | ||
<body> | ||
{{{body}}} | ||
</body> | ||
</html> |