Small flow tweaks in metro api

Reviewed By: jeanlauliac

Differential Revision: D6666057

fbshipit-source-id: 6f0b56fcb531e8c7a10c782342291b35399cac2b
This commit is contained in:
Rafael Oleza 2018-01-05 07:10:58 -08:00 committed by Facebook Github Bot
parent dad6c51f2a
commit c4d319429c
3 changed files with 6 additions and 10 deletions

View File

@ -27,7 +27,7 @@ import type {TransformVariants} from './ModuleGraph/types.flow';
import type {HasteImpl} from './node-haste/Module'; import type {HasteImpl} from './node-haste/Module';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
type Middleware = (IncomingMessage, ServerResponse, ?(?Error) => void) => void; type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed;
export type ConfigT = { export type ConfigT = {
assetRegistryPath: string, assetRegistryPath: string,

View File

@ -390,11 +390,11 @@ class Server {
return JSON.stringify(Object.assign({}, options, ignoredParams)); return JSON.stringify(Object.assign({}, options, ignoredParams));
} }
async processRequest( processRequest = async (
req: IncomingMessage, req: IncomingMessage,
res: ServerResponse, res: ServerResponse,
next?: () => mixed, 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}`);
@ -421,7 +421,7 @@ class Server {
res.writeHead(404); res.writeHead(404);
res.end(); res.end();
} }
} };
_prepareDeltaBundler( _prepareDeltaBundler(
req: IncomingMessage, req: IncomingMessage,

View File

@ -136,7 +136,6 @@ type CreateConnectMiddlewareOptions = {|
exports.createConnectMiddleware = async function( exports.createConnectMiddleware = async function(
options: CreateConnectMiddlewareOptions, options: CreateConnectMiddlewareOptions,
) { ) {
// $FlowFixMe I don't know why Flow thinks there's an error here... runMetro IS async
const metroServer = await runMetro({ const metroServer = await runMetro({
config: options.config, config: options.config,
maxWorkers: options.maxWorkers, maxWorkers: options.maxWorkers,
@ -150,10 +149,7 @@ exports.createConnectMiddleware = async function(
: Config.DEFAULT; : Config.DEFAULT;
return { return {
middleware: normalizedConfig.enhanceMiddleware( middleware: normalizedConfig.enhanceMiddleware(metroServer.processRequest),
(req: IncomingMessage, res: ServerResponse, next: ?(?Error) => void) =>
metroServer.processRequest(req, res, next),
),
end() { end() {
metroServer.end(); metroServer.end();
}, },