Skip to content

Commit

Permalink
Fix local-cli assetRegistryPath and middlewares (#20162)
Browse files Browse the repository at this point in the history
Summary:
This fixes some regressions with local-cli introduced in c4a66a8.

- We didn't pass `assetRegistryPath` which caused the following error when loading the bundle:
```
error: bundling failed: Error: Unable to resolve module `missing-asset-registry-path` from `/Users/janic/Developer/react-native/RNTester/js/uie_thumb_normal@2x.png`: Module `missing-asset-registry-path` does not exist in the Haste module map
```
- The middlewares were not added to the metro server. This causes some packager server features to fail. The one I noticed is that the /status endpoint didn't exist anymore which causes CI to fail and also Android to not load the bundle from the packager initially. The remote debugging feature was also broken.
Pull Request resolved: #20162

Differential Revision: D8867610

Pulled By: hramos

fbshipit-source-id: 8a08b7f3175692ab6ee73c0a7c25075091ae4792
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Jul 18, 2018
1 parent 04aaa01 commit f05943d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions local-cli/server/middleware/MiddlewareManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
28 changes: 21 additions & 7 deletions local-cli/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {|
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f05943d

Please sign in to comment.