Skip to content

Commit

Permalink
fix - setAuthtoken don't use binPath option (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
april418 authored and bubenshchykov committed Sep 21, 2018
1 parent 30af669 commit e637c3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -9,7 +9,7 @@ async function connect (opts) {
opts = defaults(opts);
validate(opts);
if (opts.authtoken) {
await setAuthtoken(opts.authtoken, opts.configPath);
await setAuthtoken(opts);
}
const url = await getProcess(opts);
internalApi = request.defaults({baseUrl: url});
Expand Down
17 changes: 13 additions & 4 deletions process.js
@@ -1,6 +1,7 @@
const { spawn } = require('child_process');
const platform = require('os').platform();

const defaultDir = __dirname + '/bin';
const bin = './ngrok' + (platform === 'win32' ? '.exe' : '');
const ready = /starting web service.*addr=(\d+\.\d+\.\d+\.\d+:\d+)/;
const inUse = /address already in use/;
Expand All @@ -26,7 +27,7 @@ async function getProcess(opts) {
}

async function startProcess (opts) {
let dir = __dirname + '/bin';
let dir = defaultDir;
const start = ['start', '--none', '--log=stdout'];
if (opts.region) start.push('--region=' + opts.region);
if (opts.configPath) start.push('--config=' + opts.configPath);
Expand Down Expand Up @@ -85,11 +86,19 @@ function killProcess () {
});
}

async function setAuthtoken (token, configPath) {
/**
* @param {string | INgrokOptions} optsOrToken
*/
async function setAuthtoken (optsOrToken) {
const isOpts = typeof optsOrToken !== 'string'
const opts = isOpts ? optsOrToken : {}
const token = isOpts ? opts.authtoken : optsOrToken

const authtoken = ['authtoken', token];
if (configPath) authtoken.push('--config=' + configPath);
if (opts.configPath) authtoken.push('--config=' + opts.configPath);

let dir = __dirname + '/bin';
let dir = defaultDir;
if (opts.binPath) dir = opts.binPath(dir)
const ngrok = spawn(bin, authtoken, {cwd: dir});

const killed = new Promise((resolve, reject) => {
Expand Down

0 comments on commit e637c3a

Please sign in to comment.