Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should run ganache server on passed port', async () => {
childResponse = await runCmdHandler(`etherlime ganache --port ${RUN_DIRECT_PORT}`, expectedOutput);
const portInUseAfterDirectCallRun = await tcpPortUsed.check(RUN_DIRECT_PORT);
assert.isTrue(portInUseAfterDirectCallRun, `The specific port ${RUN_DIRECT_PORT} is free`);
});
});
grunt.registerTask("startUnitTestApp", "Spawn a Maven process to start the Jetty server running the unit test application", function() {
grunt.log.writeln("Check Jetty unit test application state...");
var done = this.async();
tcpPortUsed.check(8089, "localhost")
.then(function(inUse) {
if (!inUse) {
grunt.log.writeln("Starting unit test app...");
grunt.task.run("shell:startTestApp");
done();
} else {
grunt.log.writeln("Jetty unit test application appears to be running already...");
done();
}
}, function(err) {
console.error("Unknown if Jetty unit test application is already running:", err.message);
done();
});
});
(async() => {
if (await tcpPortUsed.check(+port)) {
console.error(`ERROR: Port ${port} is in use.`);
process.exit(3)
}
if (port+'' === '443') {
https.createServer({
key: DUMMY_SSL_KEY,
cert: DUMMY_SSL_CERT
}, app)
.listen(port, function () {
console.log(`App listening on port ${port}.`)
});
} else {
app.listen(port, function () {
console.log(`App listening on port ${port}.`)
});
}
checkPort: function(devIp,devPort,cb) {
if (dlna.checkedPorts && dlna.checkedPorts.length) {
devResult = dlna.checkedPorts.some(function(el,ij) {
if (el[0] == devIp && el[1] == devPort) {
// console.log('Refound: '+devIp+' Port '+devPort+' usage: '+el[2]);
if (el[2]) cb(true);
else cb(false);
return true;
}
});
if (devResult) return;
}
if (!dlna.checkedPorts) dlna.checkedPorts = [];
require('tcp-port-used').check(parseInt(devPort), devIp)
.then(function(inUse) {
// console.log('Ip: '+devIp+' Port '+devPort+' usage: '+inUse);
dlna.checkedPorts.push([devIp,devPort,true]);
cb(true);
}, function(err) {
// console.log('Ip: '+devIp+' Port '+devPort+' Error: '+err.message);
dlna.checkedPorts.push([devIp,devPort,false]);
cb(false);
});
},
async findAvailablePort() {
const tcpPortUsed = require('tcp-port-used');
let state = null;
for (let i = 0; i < 10000; i++) {
state = randomClipperPort(state, Setting.value('env'));
const inUse = await tcpPortUsed.check(state.port);
if (!inUse) return state.port;
}
throw new Error('All potential ports are in use or not available.');
}
async function main() {
let api = new OneDriveApi('e09fc0de-c958-424f-83a2-e56a721d331b', 'FAPky27RNWYuXWwThgkQE47');
let ports = api.possibleOAuthFlowPorts();
let port = null;
for (let i = 0; i < ports.length; i++) {
let inUse = await tcpPortUsed.check(ports[i]);
if (!inUse) {
port = ports[i];
break;
}
}
if (!port) throw new Error('All potential ports are in use - please report the issue at https://github.com/laurent22/joplin');
let authCodeUrl = api.authCodeUrl('http://localhost:' + port);
let server = http.createServer((request, response) => {
const query = urlParser.parse(request.url, true).query;
function writeResponse(code, message) {
response.writeHead(code, {"Content-Type": "text/html"});
response.write(message);
grunt.registerTask('start-node-coverage-server', 'A task to start the node-coverage server (it will stay running)', function() {
if (!grunt.file.isDir(alf.coverageDirectory))
{
grunt.file.mkdir(alf.coverageDirectory);
}
var tcpPortUsed = require('tcp-port-used');
tcpPortUsed.check(8082, 'localhost')
.then(function(inUse) {
if(!inUse)
{
var nodeCoverage = grunt.util.spawn({
cmd: 'node',
args: ['node_modules/node-coverage/server.js',
'--port',
'8082',
'--report-dir',
alf.coverageDirectory],
opts: {
detached: 'true',
stdio : 'inherit'
}
}, function(error, result, code) {
grunt.log.writeln("Finished spawning node-coverage server...");
const verifyPortUnused = async (port: number) => {
const inUse = await tcpPortUsed.check(port, '127.0.0.1')
if (inUse) {
server[port].close()
}
}