diff --git a/local-cli/server/middleware/MiddlewareManager.js b/local-cli/server/middleware/MiddlewareManager.js index 5402caf6f..8692abdcc 100644 --- a/local-cli/server/middleware/MiddlewareManager.js +++ b/local-cli/server/middleware/MiddlewareManager.js @@ -19,8 +19,8 @@ const indexPageMiddleware = require('./indexPage'); const copyToClipBoardMiddleware = require('./copyToClipBoardMiddleware'); const loadRawBodyMiddleware = require('./loadRawBodyMiddleware'); const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware'); -const statusPageMiddleware = require('./statusPageMiddleware.js'); -const systraceProfileMiddleware = require('./systraceProfileMiddleware.js'); +const statusPageMiddleware = require('./statusPageMiddleware'); +const systraceProfileMiddleware = require('./systraceProfileMiddleware'); const getDevToolsMiddleware = require('./getDevToolsMiddleware'); type Options = { diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index 7f660bde2..c7ea9c64a 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -16,10 +16,14 @@ const Metro = require('metro'); const {Terminal} = require('metro-core'); +const messageSocket = require('./util/messageSocket'); const morgan = require('morgan'); const path = require('path'); +const webSocketProxy = require('./util/webSocketProxy'); const MiddlewareManager = require('./middleware/MiddlewareManager'); +const {ASSET_REGISTRY_PATH} = require('../core/Constants'); + import type {ConfigT} from 'metro'; export type Args = {| @@ -55,21 +59,31 @@ async function runServer(args: Args, config: ConfigT) { const serverInstance = await Metro.runServer({ config: { ...config, - hmrEnabled: true, - maxWorkers: args.maxWorkers, - reporter, - secure: args.https, - secureKey: args.key, - secureCert: args.cert, + assetRegistryPath: ASSET_REGISTRY_PATH, + enhanceMiddleware: middleware => + middlewareManager.getConnectInstance().use(middleware), transformModulePath: args.transformer ? path.resolve(args.transformer) : config.getTransformModulePath(), - watch: !args.nonPersistent, }, + hmrEnabled: true, host: args.host, + maxWorkers: args.maxWorkers, port: args.port, + reporter, + secure: args.https, + secureCert: args.cert, + secureKey: args.key, }); + const wsProxy = webSocketProxy.attachToServer( + serverInstance, + '/debugger-proxy', + ); + const ms = messageSocket.attachToServer(serverInstance, '/message'); + middlewareManager.attachDevToolsSocket(wsProxy); + middlewareManager.attachDevToolsSocket(ms); + // In Node 8, the default keep-alive for an HTTP connection is 5 seconds. In // early versions of Node 8, this was implemented in a buggy way which caused // some HTTP responses (like those containing large JS bundles) to be