Merge pull request #8 from michellebu/feature/restify
Switch from Express to Restify.
This commit is contained in:
commit
a0c6ec0294
@ -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,8 @@ 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._httpServer = this._app;
|
||||
|
||||
this._options = util.extend({
|
||||
port: 80,
|
||||
@ -180,26 +180,23 @@ PeerServer.prototype._checkKey = function(key, ip, cb) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 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);
|
||||
});
|
||||
|
||||
|
||||
// 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 +215,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 +248,7 @@ PeerServer.prototype._initializeHTTP = function() {
|
||||
});
|
||||
res.send(200);
|
||||
}
|
||||
return next();
|
||||
};
|
||||
|
||||
this._app.post('/:key/:id/:token/offer', handle);
|
||||
@ -264,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);
|
||||
|
||||
};
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user