From 00b41d6d028baeb77e0b82fb41a0b8497f7506ed Mon Sep 17 00:00:00 2001 From: David Gage Date: Tue, 2 Apr 2013 16:50:25 -0400 Subject: [PATCH 1/2] got this working with restify (as far as I can tell anyway) --- lib/server.js | 26 ++++++++++++++++---------- package.json | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/server.js b/lib/server.js index eae620f..7e093e4 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,5 +1,5 @@ var util = require('./util'); -var express = require('express'); +var restify = require('restify'); var http = require('http'); var EventEmitter = require('events').EventEmitter; var WebSocketServer = require('ws').Server; @@ -9,8 +9,9 @@ function PeerServer(options) { if (!(this instanceof PeerServer)) return new PeerServer(options); EventEmitter.call(this); - this._app = express(); - this._httpServer = http.createServer(this._app); + this._app = restify.createServer(); + //this._app = express(); + this._httpServer = this._app; this._options = util.extend({ port: 80, @@ -180,26 +181,29 @@ PeerServer.prototype._checkKey = function(key, ip, cb) { } } - +//This is where we change to restify /** Initialize HTTP server routes. */ PeerServer.prototype._initializeHTTP = function() { var self = this; - this._app.use(express.bodyParser()); + //this._app.use(express.bodyParser()); this._app.use(util.allowCrossDomain); - this._app.options('/*', function(req, res, next) { + /*this._app.options('/*', function(req, res, next) { res.send(200); - }); + return next(); + });*/ // Retrieve guaranteed random ID. - this._app.get('/:key/id', function(req, res) { + this._app.get('/:key/id', function(req, res, next) { + res.contentType = 'text/html'; res.send(self._generateClientId(req.params.key)); + return next(); }); // Server sets up HTTP streaming when you get post an ID. - this._app.post('/:key/:id/:token/id', function(req, res) { + this._app.post('/:key/:id/:token/id', function(req, res, next) { var id = req.params.id; var token = req.params.token; var key = req.params.key; @@ -218,10 +222,11 @@ PeerServer.prototype._initializeHTTP = function() { } else { self._startStreaming(res, key, id, token); } + return next(); }); - var handle = function(req, res) { + var handle = function(req, res, next) { var key = req.params.key; var id = req.params.id; @@ -250,6 +255,7 @@ PeerServer.prototype._initializeHTTP = function() { }); res.send(200); } + return next(); }; this._app.post('/:key/:id/:token/offer', handle); diff --git a/package.json b/package.json index 8a36e88..42d2258 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "author": "Michelle Bu, Eric Zhang", "license": "MIT", "dependencies": { - "ws": "~0.4.25", - "express": "~3.1.0" + "restify": "~2.3.5", + "ws": "~0.4.25" } } From 24805444ccbde8714b96d0a0df288756f72a22d9 Mon Sep 17 00:00:00 2001 From: Michelle Bu Date: Fri, 5 Apr 2013 11:12:07 -0700 Subject: [PATCH 2/2] restify fixes --- lib/server.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/server.js b/lib/server.js index 7e093e4..88b641a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -10,7 +10,6 @@ function PeerServer(options) { EventEmitter.call(this); this._app = restify.createServer(); - //this._app = express(); this._httpServer = this._app; this._options = util.extend({ @@ -181,20 +180,14 @@ PeerServer.prototype._checkKey = function(key, ip, cb) { } } -//This is where we change to restify /** Initialize HTTP server routes. */ PeerServer.prototype._initializeHTTP = function() { var self = this; - //this._app.use(express.bodyParser()); + this._app.use(restify.bodyParser({ mapParams: false })); + this._app.use(restify.queryParser()) this._app.use(util.allowCrossDomain); - - /*this._app.options('/*', function(req, res, next) { - res.send(200); - return next(); - });*/ - // Retrieve guaranteed random ID. this._app.get('/:key/id', function(req, res, next) { res.contentType = 'text/html'; @@ -270,7 +263,7 @@ PeerServer.prototype._initializeHTTP = function() { //this._app.post('/port', handle); - // Listen on user-specified port and + // Listen on user-specified port. this._httpServer.listen(this._options.port); };