Do not assume we are using processRequest in an express app

Summary: It might be that Metro bundler is getting used directly with the `http` module and not within an express app. If that's the case, the `next` method will not exist, so we have to guard against it.

Reviewed By: davidaurelio

Differential Revision: D5639944

fbshipit-source-id: bcee4a70f6a7b643218b11af0d8aedbc7762eead
This commit is contained in:
Miguel Jimenez Esun 2017-08-17 04:32:00 -07:00 committed by Facebook Github Bot
parent e4acb91914
commit b3b2d10500
1 changed files with 10 additions and 2 deletions

View File

@ -700,7 +700,11 @@ class Server {
return this._reportBundlePromise(buildID, options, bundleFromScratch()); return this._reportBundlePromise(buildID, options, bundleFromScratch());
} }
processRequest(req: IncomingMessage, res: ServerResponse, next: () => mixed) { processRequest(
req: IncomingMessage,
res: ServerResponse,
next?: () => mixed,
) {
const urlObj = url.parse(req.url, true); const urlObj = url.parse(req.url, true);
const {host} = req.headers; const {host} = req.headers;
debug(`Handling request: ${host ? 'http://' + host : ''}${req.url}`); debug(`Handling request: ${host ? 'http://' + host : ''}${req.url}`);
@ -726,9 +730,13 @@ class Server {
} else if (pathname === '/symbolicate') { } else if (pathname === '/symbolicate') {
this._symbolicate(req, res); this._symbolicate(req, res);
return; return;
} else { } else if (next) {
next(); next();
return; return;
} else {
res.writeHead(404);
res.end();
return;
} }
const options = this._getOptionsFromUrl(req.url); const options = this._getOptionsFromUrl(req.url);