From b3b2d10500d3a0caf21e024cd40452ed99c3dedc Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Thu, 17 Aug 2017 04:32:00 -0700 Subject: [PATCH] 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 --- packages/metro-bundler/src/Server/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 60592aa3..a846b141 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -700,7 +700,11 @@ class Server { 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 {host} = req.headers; debug(`Handling request: ${host ? 'http://' + host : ''}${req.url}`); @@ -726,9 +730,13 @@ class Server { } else if (pathname === '/symbolicate') { this._symbolicate(req, res); return; - } else { + } else if (next) { next(); return; + } else { + res.writeHead(404); + res.end(); + return; } const options = this._getOptionsFromUrl(req.url);