Unify oss and internal version of base body loader middleware

Reviewed By: @amasad

Differential Revision: D2519637

fb-gh-sync-id: 88f23c33a1ca0423852ce8ed7696df811e3f8d27
This commit is contained in:
Martín Bigio 2015-10-08 14:15:20 -07:00 committed by facebook-github-bot-4
parent cd33f0d269
commit c9317c1445
2 changed files with 24 additions and 14 deletions

22
loadRawBodyMiddleware.js Normal file
View File

@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
module.exports = function(req, res, next) {
req.rawBody = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
req.rawBody += chunk;
});
req.on('end', function() {
next();
});
};

View File

@ -21,6 +21,7 @@ const cpuProfilerMiddleware = require('./cpuProfilerMiddleware');
const connect = require('connect');
const formatBanner = require('./formatBanner');
const getDevToolsMiddleware = require('./getDevToolsMiddleware');
const loadRawBodyMiddleware = require('./loadRawBodyMiddleware');
const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware');
const parseCommandLine = require('./parseCommandLine.js');
const ReactPackager = require('./react-packager');
@ -157,19 +158,6 @@ var server = runServer(options, function() {
webSocketProxy.attachToServer(server, '/debugger-proxy');
function loadRawBody(req, res, next) {
req.rawBody = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
req.rawBody += chunk;
});
req.on('end', function() {
next();
});
}
function getAppMiddleware(options) {
var transformerPath = options.transformer;
if (!isAbsolutePath(transformerPath)) {
@ -198,7 +186,7 @@ function runServer(
readyCallback
) {
var app = connect()
.use(loadRawBody)
.use(loadRawBodyMiddleware)
.use(getDevToolsMiddleware(options))
.use(openStackFrameInEditorMiddleware)
.use(statusPageMiddleware)