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 0a835b7994
commit 42d756310a
2 changed files with 24 additions and 14 deletions

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 connect = require('connect');
const formatBanner = require('./formatBanner'); const formatBanner = require('./formatBanner');
const getDevToolsMiddleware = require('./getDevToolsMiddleware'); const getDevToolsMiddleware = require('./getDevToolsMiddleware');
const loadRawBodyMiddleware = require('./loadRawBodyMiddleware');
const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware'); const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware');
const parseCommandLine = require('./parseCommandLine.js'); const parseCommandLine = require('./parseCommandLine.js');
const ReactPackager = require('./react-packager'); const ReactPackager = require('./react-packager');
@ -157,19 +158,6 @@ var server = runServer(options, function() {
webSocketProxy.attachToServer(server, '/debugger-proxy'); 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) { function getAppMiddleware(options) {
var transformerPath = options.transformer; var transformerPath = options.transformer;
if (!isAbsolutePath(transformerPath)) { if (!isAbsolutePath(transformerPath)) {
@ -198,7 +186,7 @@ function runServer(
readyCallback readyCallback
) { ) {
var app = connect() var app = connect()
.use(loadRawBody) .use(loadRawBodyMiddleware)
.use(getDevToolsMiddleware(options)) .use(getDevToolsMiddleware(options))
.use(openStackFrameInEditorMiddleware) .use(openStackFrameInEditorMiddleware)
.use(statusPageMiddleware) .use(statusPageMiddleware)