How to use the metro.runServer function in metro

To help you get started, we’ve selected a few metro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-native-community / cli / packages / cli / src / server / runServer.js View on Github external
const middlewareManager = new MiddlewareManager({
    host: args.host,
    port: metroConfig.server.port,
    watchFolders: metroConfig.watchFolders,
  });

  middlewareManager.getConnectInstance().use(morgan('combined'));

  metroConfig.watchFolders.forEach(
    middlewareManager.serveStatic.bind(middlewareManager)
  );

  metroConfig.server.enhanceMiddleware = middleware =>
    middlewareManager.getConnectInstance().use(middleware);

  const serverInstance = await Metro.runServer(metroConfig, {
    host: args.host,
    secure: args.https,
    secureCert: args.cert,
    secureKey: args.key,
    hmrEnabled: true,
  });

  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
github godaddy / ekke / api / server.js View on Github external
module.exports = async function metro(data) {
  const config = await configure(data);

  //
  // Metro inconsistencies:
  //
  // You can configure the `host` through the server config object, but not
  // the port number. They are extracting that from `config.server` object.
  // To provide consistency in the configuration we're going to forcefully
  // override the config.server with our own config data:
  //
  config.server.port = data.port;
  config.server.enableVisualizer = false;
  config.server.runInspectorProxy = false;

  const server = await Metro.runServer(config, {
    hmrEnabled: false,
    host: data.hostname
  });

  //
  // Ideally we want to piggyback the WebSocket servers that Metro creates,
  // but unfortunately there is no way to get into their instances, and they
  // don't listen to responses from the server, which is something that we
  // need in order to stream back the test results.
  //
  const ws = new WebSocketServer({
    path: '/ekke',
    server
  });

  return { ws, server };
github rafeca / metro-sample-app / scripts / server.js View on Github external
'use strict';

const path = require('path');
const metro = require('metro');

const ROOT = path.resolve(path.join(__dirname, '..'));

metro.runServer({
  port: '8082',
  projectRoots: [path.join(ROOT, 'src')],
  config: {
    getTransformModulePath: () => require.resolve('metro/src/defaultTransform'),
  },
}).then(() => {
  console.log('Metro server listening!');
}).catch(err => {
  console.log(err);
});
github react-native-community / cli / packages / cli / src / commands / server / runServer.ts View on Github external
metroConfig.watchFolders.forEach(
    middlewareManager.serveStatic.bind(middlewareManager),
  );

  const customEnhanceMiddleware = metroConfig.server.enhanceMiddleware;

  metroConfig.server.enhanceMiddleware = (middleware: any, server: unknown) => {
    if (customEnhanceMiddleware) {
      middleware = customEnhanceMiddleware(middleware, server);
    }

    return middlewareManager.getConnectInstance().use(middleware);
  };

  const serverInstance = await Metro.runServer(metroConfig, {
    host: args.host,
    secure: args.https,
    secureCert: args.cert,
    secureKey: args.key,
    hmrEnabled: true,
  });

  const wsProxy = webSocketProxy.attachToServer(
    serverInstance,
    '/debugger-proxy',
  );
  const ms = messageSocket.attachToServer(serverInstance, '/message');
  middlewareManager.attachDevToolsSocket(wsProxy);
  middlewareManager.attachDevToolsSocket(ms);

  middlewareManager