Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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 };
'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);
});
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