Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert(error === null);
if (error) assert(error.message === '');
assert(port === 3005);
};
const assertPort = (port: number) => {
assert(port === 3005);
};
// one argument
findAPortNotInUse([3000, 3005, 3006]).then(assertPort);
findAPortNotInUse(3000).then(assertPort);
// two arguments
findAPortNotInUse([3000, 3005, 3006], findPortCallback);
findAPortNotInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, findPortCallback);
findAPortNotInUse(3000, '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, 3010).then(assertPort);
// three arguments
findAPortNotInUse(3000, 3010, '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, 3010, findPortCallback);
// four argumentss
findAPortNotInUse(3000, 3010, '127.0.0.1', findPortCallback);
// one argument
findAPortInUse([3000, 3005, 3006]).then(assertPort);
findAPortInUse(3000).then(assertPort);
const assertPort = (port: number) => {
assert(port === 3005);
};
// one argument
findAPortNotInUse([3000, 3005, 3006]).then(assertPort);
findAPortNotInUse(3000).then(assertPort);
// two arguments
findAPortNotInUse([3000, 3005, 3006], findPortCallback);
findAPortNotInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, findPortCallback);
findAPortNotInUse(3000, '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, 3010).then(assertPort);
// three arguments
findAPortNotInUse(3000, 3010, '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, 3010, findPortCallback);
// four argumentss
findAPortNotInUse(3000, 3010, '127.0.0.1', findPortCallback);
// one argument
findAPortInUse([3000, 3005, 3006]).then(assertPort);
findAPortInUse(3000).then(assertPort);
// two arguments
findAPortInUse([3000, 3005, 3006], findPortCallback);
findAPortInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort);
checkPortStatus(3000, '127.0.0.1', { timeout: 400 }).then(assertStatus);
checkPortStatus(3000, '127.0.0.1', { timeout: 400 }, checkPortCallback);
const findPortCallback = (error: Error | null, port: number) => {
assert(error === null);
if (error) assert(error.message === '');
assert(port === 3005);
};
const assertPort = (port: number) => {
assert(port === 3005);
};
// one argument
findAPortNotInUse([3000, 3005, 3006]).then(assertPort);
findAPortNotInUse(3000).then(assertPort);
// two arguments
findAPortNotInUse([3000, 3005, 3006], findPortCallback);
findAPortNotInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, findPortCallback);
findAPortNotInUse(3000, '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, 3010).then(assertPort);
// three arguments
findAPortNotInUse(3000, 3010, '127.0.0.1').then(assertPort);
findAPortNotInUse(3000, 3010, findPortCallback);
// four argumentss
findAPortNotInUse(3000, 3010, '127.0.0.1', findPortCallback);
.option('-m --main [n]', 'application main entry')
.option('-c --stylesheets [n]', 'application stylesheets entry')
.option('-h --host [n]', 'dev server address')
.option('-p --port [n]', 'dev server port')
.option('-t --template [n]', 'dev server html template file')
.option('-r --reactor-host [n]', 'elm-reactor address')
.option('-u --reactor-port [n]', 'elm-reactor port')
.parse(process.argv)
// load the dev tasks
const opts = program.opts()
opts.host || opts.port
? dev(opts) && gulp.start('dev')
: portscanner.findAPortNotInUse(8000, 9000).then(port => {
portscanner.findAPortNotInUse(8010, 9000).then(reactorPort => {
dev(Object.assign({}, opts, {port, reactorPort}))
gulp.start('dev')
})
})
import portscanner from 'portscanner';
import serveStatic from 'serve-static';
// Configuration for the server.
const PORT = 9999;
const MAX_PORT = PORT + 100;
const HOST = '127.0.0.1'
const app = connect();
// update mimetype
serveStatic.mime.define({'application/wasm': ['wasm']});
app.use(serveStatic(path.join(__dirname, '..')));
portscanner.findAPortNotInUse(PORT, MAX_PORT, HOST, (error, port) => {
if (error) {
throw error;
}
process.stdout.write(`Serving on http://${HOST}:${port}` + '\n\n');
app.listen(port);
});
function getAvailablePort(callback)
{
portscanner.findAPortNotInUse(3000, 3030, host, function(error, port)
{
if (error) throw error;
callback(port);
})
}
ipc.on('upload', (event, folderPath, uId, spectatorMode, bandwidth) => {
folder = folderPath;
userId = uId;
spectator = spectatorMode;
console.log('upload', folder, userId, spectator, bandwidth);
if (bandwidth !== 0) {
portscanner.findAPortNotInUse(50000, 60000, (err, port) => {
if (err) {
console.error(err);
Sentry.captureException(err);
}
createProxy(err ? 1080 : port, bandwidth);
AWS.config.update({
httpOptions: { agent: proxyAgent(`socks5://localhost:${err ? 1080 : port}`) },
});
uploadFolder(folder, userId, spectator);
});
} else {
uploadFolder(folder, userId, spectator);
}
});
function findUnusedPort(port, maxPort, hostname, callback) {
if (hostname === '0.0.0.0') {
hostname = '127.0.0.1';
}
if (port === 0) {
async.nextTick(function() {
callback(null, 0);
});
} else {
portscanner.findAPortNotInUse(port, maxPort, hostname, callback);
}
}
const generateServicePort = (serviceId) => {
return portscanner.findAPortNotInUse(8100, 49151, '127.0.0.1')
.then((newPort) => {
services[serviceId].port = newPort;
return newPort;
});
};