From c4d319429cb426755db69ea9f5fb61a8f470d34b Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Fri, 5 Jan 2018 07:10:58 -0800 Subject: [PATCH] Small flow tweaks in metro api Reviewed By: jeanlauliac Differential Revision: D6666057 fbshipit-source-id: 6f0b56fcb531e8c7a10c782342291b35399cac2b --- packages/metro/src/Config.js | 2 +- packages/metro/src/Server/index.js | 8 ++++---- packages/metro/src/index.js | 6 +----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/metro/src/Config.js b/packages/metro/src/Config.js index fb96e0e4..dfe78811 100644 --- a/packages/metro/src/Config.js +++ b/packages/metro/src/Config.js @@ -27,7 +27,7 @@ import type {TransformVariants} from './ModuleGraph/types.flow'; import type {HasteImpl} from './node-haste/Module'; import type {IncomingMessage, ServerResponse} from 'http'; -type Middleware = (IncomingMessage, ServerResponse, ?(?Error) => void) => void; +type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed; export type ConfigT = { assetRegistryPath: string, diff --git a/packages/metro/src/Server/index.js b/packages/metro/src/Server/index.js index d63e9cf3..853dd9f0 100644 --- a/packages/metro/src/Server/index.js +++ b/packages/metro/src/Server/index.js @@ -390,11 +390,11 @@ class Server { return JSON.stringify(Object.assign({}, options, ignoredParams)); } - async processRequest( + processRequest = async ( req: IncomingMessage, res: ServerResponse, - next?: () => mixed, - ) { + next: ?() => mixed, + ) => { const urlObj = url.parse(req.url, true); const {host} = req.headers; debug(`Handling request: ${host ? 'http://' + host : ''}${req.url}`); @@ -421,7 +421,7 @@ class Server { res.writeHead(404); res.end(); } - } + }; _prepareDeltaBundler( req: IncomingMessage, diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index 90c87f3a..288e452d 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -136,7 +136,6 @@ type CreateConnectMiddlewareOptions = {| exports.createConnectMiddleware = async function( options: CreateConnectMiddlewareOptions, ) { - // $FlowFixMe I don't know why Flow thinks there's an error here... runMetro IS async const metroServer = await runMetro({ config: options.config, maxWorkers: options.maxWorkers, @@ -150,10 +149,7 @@ exports.createConnectMiddleware = async function( : Config.DEFAULT; return { - middleware: normalizedConfig.enhanceMiddleware( - (req: IncomingMessage, res: ServerResponse, next: ?(?Error) => void) => - metroServer.processRequest(req, res, next), - ), + middleware: normalizedConfig.enhanceMiddleware(metroServer.processRequest), end() { metroServer.end(); },