got this working with restify (as far as I can tell anyway)

This commit is contained in:
David Gage 2013-04-02 16:50:25 -04:00
parent 8f2f7cef6f
commit 00b41d6d02
2 changed files with 18 additions and 12 deletions

View File

@ -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);

View File

@ -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"
}
}