Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
value: _asyncToGenerator(function* () {
var _this = this;
if (this._ngrokUrl) {
console.log("Waiting for ngrok to disconnect...");
yield this._stopNgrokAsync();
console.log("Disconnected ngrok; restarting...");
}
this.ngrokReady$ = new _Promise(function (fulfill, reject) {
_this._ngrokReadyFulfill = fulfill;
_this._ngrokReadyReject = reject;
});
this.emit('ngrok-will-start', this.opts.port);
this.ngrokReady$ = ngrok.promise.connect(this.opts.port);
// this._setCombinedPromises();
this._ngrokUrl = yield this.ngrokReady$;
this.emit('ngrok-did-start', this.opts.port, this._ngrokUrl);
this.emit('ngrok-ready', this.opts.port, this._ngrokUrl);
console.log("Connected ngrok to port " + this.opts.port + " via " + this._ngrokUrl);
return this._ngrokUrl;
})
}, {
async _stopNgrokAsync() {
if (this._ngrokUrl) {
this.emit('ngrok-will-disconnect', this._ngrokUrl);
try {
await ngrok.promise.disconnect(this._ngrokUrl);
let oldNgrokUrl = this._ngrokUrl;
this._ngrokUrl = null;
// this._ngrokDisconnectedFulfill(oldNgrokUrl);
// console.log("Disconnected ngrok");
this.emit('ngrok-disconnected', oldNgrokUrl);
} catch (e) {
console.error("Problem disconnecting ngrok:", e);
// this._ngrokDisconnectedReject(e);
this.emit('ngrok-disconnect-err', e);
}
}
}
value: _asyncToGenerator(function* () {
if (this._ngrokUrl) {
this.emit('ngrok-will-disconnect', this._ngrokUrl);
try {
yield ngrok.promise.disconnect(this._ngrokUrl);
var oldNgrokUrl = this._ngrokUrl;
this._ngrokUrl = null;
// this._ngrokDisconnectedFulfill(oldNgrokUrl);
// console.log("Disconnected ngrok");
this.emit('ngrok-disconnected', oldNgrokUrl);
} catch (e) {
console.error("Problem disconnecting ngrok:", e);
// this._ngrokDisconnectedReject(e);
this.emit('ngrok-disconnect-err', e);
}
}
})
}, {
let oldNgrokUrl = this._ngrokUrl;
this._ngrokUrl = null;
// this._ngrokDisconnectedFulfill(oldNgrokUrl);
// console.log("Disconnected ngrok");
this.emit('ngrok-disconnected', oldNgrokUrl);
} catch (e) {
console.error("Problem disconnecting ngrok:", e);
// this._ngrokDisconnectedReject(e);
this.emit('ngrok-disconnect-err', e);
}
}
if (this._packagerNgrokUrl) {
this.emit('packager-ngrok-will-disconnect', this._packagerNgrokUrl);
try {
await ngrok.promise.disconnect(this._packagerNgrokUrl);
let oldNgrokUrl = this._packagerNgrokUrl;
this._packagerNgrokUrl = null;
// this._ngrokDisconnectedFulfill(oldNgrokUrl);
// console.log("Disconnected ngrok");
this.emit('packager-ngrok-disconnected', oldNgrokUrl);
} catch (e) {
console.error("Problem disconnecting packager ngrok:", e);
// this._ngrokDisconnectedReject(e);
this.emit('packager-ngrok-disconnect-err', e);
}
}
}
}
// TODO: These two functions are sort of redundant
var mainModulePath = yield urlUtil.guessMainModulePathAsync();
var entryPoint = yield urlUtil.entryPointAsync();
log(crayon.gray("Using mainModulePath of", mainModulePath, "and an entry point of", entryPoint));
var ngrokSubdomain = argv['ngrok-subdomain'] || config.ngrok && config.ngrok.subdomain || undefined;
var ngrokAuthToken = argv['ngrok-auth-token'] || config.ngrok && config.ngrok.authToken || undefined;
var port = argv.port;
if (port == null) {
port = 9000 + Math.floor(Math.random() * 1000);
}
var urlP = ngrok.promise.connect({
port: port,
authtoken: ngrokAuthToken,
subdomain: ngrokSubdomain
});
//var root = path.resolve(__dirname, '..', '..');
var root = config.absolutePath;
var packager = child_process.spawn(config.packagerPath, ["--port=" + port, "--root=" + root, "--assetRoots=" + root], {
stdio: [process.stdin, 'pipe', process.stderr]
});
var outStream = new stream.Writable();
outStream.buffer = '';
outStream._write = function (chunk, encoding, done) {
outStream.buffer += chunk.toString();
done();
async function _serve(opts) {
var expSettings = await config.expInfoFile.readAsync();
opts = opts || {};
var port = opts.port || expSettings.port || await freeportAsync(6080);
var pc = new PackagerController({port});
var pcStart$ = pc.startAsync();
var ngrokUrl$ = ngrok.promise.connect({port});
try {
var [_ready, ngrokBaseUrl, lanIp, entryPoint, mainModulePath] = await Promise.all([
pc.packagerReady,
ngrokUrl$,
network.privateIpAsync(),
urlUtil.entryPointAsync(),
urlUtil.guessMainModulePathAsync(),
]);
} catch (e) {
// Shutdown packager
var packagerShutdown$ = new Promise(function (fulfill, reject) {
log("Attempting to shut down packager (" + pc._packager.pid + ")...");
pc._packager.on('exit', function (code) {
log("packager shut down.");
async _startNgrokAsync() {
return await ngrok.promise.connect(this.opts.port);
}
ngrokUrl$.then(function (ngrokBaseUrl) {
log('Shutting down ngrok...');
return ngrok.promise.disconnect(ngrokBaseUrl).then(function (x) {
log('ngrok shutdown.');
fulfill(x);
}, function (err) {
log.error('Disconnecting from ngrok failed', err);
});
})['catch'](function (err) {
log.error('Failed to shutdown ngrok', err.message);
value: _asyncToGenerator(function* () {
return yield ngrok.promise.connect(this.opts.port);
})
}, {