diff --git a/loadRawBodyMiddleware.js b/loadRawBodyMiddleware.js new file mode 100644 index 00000000..2b59195f --- /dev/null +++ b/loadRawBodyMiddleware.js @@ -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(); + }); +}; diff --git a/packager.js b/packager.js index 77bef9e4..fe162737 100644 --- a/packager.js +++ b/packager.js @@ -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)