2018-08-01 01:50:18 +08:00
|
|
|
const config = require('./config');
|
|
|
|
const utils = require('./utils');
|
2019-07-07 16:49:34 +08:00
|
|
|
const env = require('./env');
|
|
|
|
const portscanner = require('portscanner');
|
|
|
|
|
|
|
|
let environmentPort;
|
|
|
|
|
|
|
|
if (process.env.TRILIUM_PORT) {
|
|
|
|
environmentPort = parseInt(process.env.TRILIUM_PORT);
|
|
|
|
}
|
2018-08-01 01:50:18 +08:00
|
|
|
|
|
|
|
if (utils.isElectron()) {
|
2019-07-07 16:49:34 +08:00
|
|
|
module.exports = new Promise((resolve, reject) => {
|
|
|
|
const startingPort = environmentPort || (env.isDev() ? 37740 : 37840);
|
|
|
|
|
|
|
|
portscanner.findAPortNotInUse(startingPort, startingPort + 10, '127.0.0.1', function(error, port) {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resolve(port);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2018-08-01 01:50:18 +08:00
|
|
|
}
|
|
|
|
else {
|
2019-07-07 16:49:34 +08:00
|
|
|
module.exports = Promise.resolve(environmentPort || config['Network']['port'] || '3000');
|
2018-08-01 01:50:18 +08:00
|
|
|
}
|