Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions download.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ declare module "ngrok/download" {
export default function downloadNgrok(
callback: (err?: Error) => void,
options?: {
cafilePath: string;
arch: string;
cdnUrl: string;
cdnPath: string;
ignoreCache: boolean;
cafilePath?: string;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only new addition are the last two lines. The other lines are made optional to reflect reality.

arch?: string;
cdnUrl?: string;
cdnPath?: string;
ignoreCache?: boolean;
cacheDir?: string;
binDir?: string;
}
): void;
}
24 changes: 14 additions & 10 deletions download.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ function downloadNgrok(callback, options) {

function getCacheUrl() {
let dir;
try {
dir =
os.platform() === "win32" && process.env.APPDATA
? path.join(process.env.APPDATA, "ngrok")
: path.join(os.homedir(), ".ngrok");
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
fs.mkdirSync(dir);

if (options.cacheDir) dir = options.cacheDir;
else {
try {
dir =
os.platform() === "win32" && process.env.APPDATA
? path.join(process.env.APPDATA, "ngrok")
: path.join(os.homedir(), ".ngrok");
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
fs.mkdirSync(dir);
}
} catch (err) {
dir = path.join(__dirname, "bin");
}
} catch (err) {
dir = path.join(__dirname, "bin");
}
const name = Buffer.from(cdnUrl).toString("base64");
return path.join(dir, name + ".zip");
Expand Down Expand Up @@ -147,7 +151,7 @@ function downloadNgrok(callback, options) {

function extract(cb) {
console.error("ngrok - unpacking binary");
const moduleBinPath = path.join(__dirname, "bin");
const moduleBinPath = options.binDir || path.join(__dirname, "bin");
extract_zip(cacheUrl, { dir: moduleBinPath })
.then(() => {
const suffix = os.platform() === "win32" ? ".exe" : "";
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ declare module "ngrok" {
gauge: number;
}

interface HTTPRequests extends Metrics {}
interface HTTPRequests extends Metrics { }

interface Tunnel {
name: string;
Expand All @@ -203,7 +203,7 @@ declare module "ngrok" {

interface CapturedRequestOptions {
limit: number;
tunnel_name: string;
tunnel_name?: string;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed during development, the tunnnel_name isn't really required

}

interface Request {
Expand Down