Only parser JSON from body when needed

This commit is contained in:
lmb 2014-10-18 16:25:06 +01:00
parent 9429006ee4
commit 9b9c6f168a

View File

@ -140,8 +140,6 @@ app._checkKey = function(key, ip, cb) {
app._initializeHTTP = function() {
var self = this;
this.use(bodyParser.urlencoded({extended: true}));
this.use(bodyParser.json());
this.use(util.allowCrossDomain);
// Retrieve guaranteed random ID.
@ -219,13 +217,15 @@ app._initializeHTTP = function() {
}
};
this.post('/:key/:id/:token/offer', handle);
var jsonParser = bodyParser.json();
this.post('/:key/:id/:token/candidate', handle);
this.post('/:key/:id/:token/offer', jsonParser, handle);
this.post('/:key/:id/:token/answer', handle);
this.post('/:key/:id/:token/candidate', jsonParser, handle);
this.post('/:key/:id/:token/leave', handle);
this.post('/:key/:id/:token/answer', jsonParser, handle);
this.post('/:key/:id/:token/leave', jsonParser, handle);
};
/** Saves a streaming response and takes care of timeouts and headers. */