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 {IncomingMessage, ServerResponse} from 'http';
type Middleware = (IncomingMessage, ServerResponse, ?(?Error) => void) => void;
type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed;
export type ConfigT = {
assetRegistryPath: string,

View File

@ -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,

View File

@ -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();
},