@ngrok/ngrok 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/.prettierrc.json +3 -0
  2. package/CHANGELOG.md +5 -0
  3. package/Cargo.toml +1 -1
  4. package/README.md +35 -1
  5. package/RELEASE.md +3 -3
  6. package/docs/assets/style.css +4 -5
  7. package/docs/classes/NgrokHttpTunnel.html +9 -9
  8. package/docs/classes/NgrokHttpTunnelBuilder.html +21 -21
  9. package/docs/classes/NgrokLabeledTunnel.html +8 -8
  10. package/docs/classes/NgrokLabeledTunnelBuilder.html +4 -4
  11. package/docs/classes/NgrokSession.html +7 -7
  12. package/docs/classes/NgrokSessionBuilder.html +15 -15
  13. package/docs/classes/NgrokTcpTunnel.html +9 -9
  14. package/docs/classes/NgrokTcpTunnelBuilder.html +8 -8
  15. package/docs/classes/NgrokTlsTunnel.html +9 -9
  16. package/docs/classes/NgrokTlsTunnelBuilder.html +10 -10
  17. package/docs/classes/UpdateRequest.html +3 -3
  18. package/docs/functions/consoleLog.html +1 -1
  19. package/docs/functions/listen.html +1 -1
  20. package/docs/functions/listenable.html +1 -1
  21. package/docs/functions/loggingCallback.html +1 -1
  22. package/docs/index.html +39 -1
  23. package/examples/express/ngrok-express-quickstart.js +11 -0
  24. package/examples/express/ngrok-express.js +28 -0
  25. package/examples/express/package.json +7 -0
  26. package/examples/fastify/ngrok-fastify.js +26 -0
  27. package/examples/fastify/package.json +7 -0
  28. package/examples/hapi/ngrok-hapi.js +35 -0
  29. package/examples/hapi/package.json +7 -0
  30. package/examples/koa/ngrok-koa.js +12 -0
  31. package/examples/koa/package.json +7 -0
  32. package/examples/nestjs/.eslintrc.js +25 -0
  33. package/examples/nestjs/.prettierrc +4 -0
  34. package/examples/nestjs/README.md +73 -0
  35. package/examples/nestjs/nest-cli.json +8 -0
  36. package/examples/nestjs/package-lock.json +12138 -0
  37. package/examples/nestjs/package.json +70 -0
  38. package/examples/nestjs/src/app.controller.spec.ts +22 -0
  39. package/examples/nestjs/src/app.controller.ts +12 -0
  40. package/examples/nestjs/src/app.module.ts +10 -0
  41. package/examples/nestjs/src/app.service.ts +8 -0
  42. package/examples/nestjs/src/main.ts +17 -0
  43. package/examples/nestjs/test/app.e2e-spec.ts +24 -0
  44. package/examples/nestjs/test/jest-e2e.json +9 -0
  45. package/examples/nestjs/tsconfig.build.json +4 -0
  46. package/examples/nestjs/tsconfig.json +21 -0
  47. package/examples/nextjs/next.config.js +12 -0
  48. package/examples/nextjs/ngrok.config.js +23 -0
  49. package/examples/nextjs/package.json +6 -0
  50. package/examples/nextjs/pages/index.js +5 -0
  51. package/examples/ngrok-http-full.js +28 -20
  52. package/examples/ngrok-http-minimum.js +21 -13
  53. package/examples/ngrok-labeled.js +21 -17
  54. package/examples/ngrok-listen.js +5 -6
  55. package/examples/ngrok-tcp.js +21 -17
  56. package/examples/ngrok-tls.js +22 -19
  57. package/examples/ngrok-typescript.ts +31 -26
  58. package/examples/ngrok-windows-pipe.js +22 -14
  59. package/examples/ngrok-winston.js +9 -9
  60. package/examples/package.json +11 -0
  61. package/examples/remix/.eslintrc.js +4 -0
  62. package/examples/remix/README.md +53 -0
  63. package/examples/remix/app/entry.client.tsx +18 -0
  64. package/examples/remix/app/entry.server.tsx +101 -0
  65. package/examples/remix/app/root.tsx +20 -0
  66. package/examples/remix/app/routes/_index.tsx +30 -0
  67. package/examples/remix/ngrok.config.js +16 -0
  68. package/examples/remix/package.json +30 -0
  69. package/examples/remix/public/favicon.ico +0 -0
  70. package/examples/remix/remix.config.js +16 -0
  71. package/examples/remix/remix.env.d.ts +2 -0
  72. package/examples/remix/tsconfig.json +22 -0
  73. package/examples/svelte/README.md +38 -0
  74. package/examples/svelte/jsconfig.json +17 -0
  75. package/examples/svelte/ngrok.config.cjs +18 -0
  76. package/examples/svelte/package.json +22 -0
  77. package/examples/svelte/src/app.d.ts +12 -0
  78. package/examples/svelte/src/app.html +12 -0
  79. package/examples/svelte/src/routes/+page.svelte +2 -0
  80. package/examples/svelte/static/favicon.png +0 -0
  81. package/examples/svelte/svelte.config.js +14 -0
  82. package/examples/svelte/vite.config.js +6 -0
  83. package/examples/vue/.vscode/extensions.json +3 -0
  84. package/examples/vue/README.md +40 -0
  85. package/examples/vue/env.d.ts +1 -0
  86. package/examples/vue/index.html +13 -0
  87. package/examples/vue/ngrok.config.ts +18 -0
  88. package/examples/vue/package.json +25 -0
  89. package/examples/vue/public/favicon.ico +0 -0
  90. package/examples/vue/src/App.vue +47 -0
  91. package/examples/vue/src/assets/base.css +74 -0
  92. package/examples/vue/src/assets/logo.svg +1 -0
  93. package/examples/vue/src/assets/main.css +35 -0
  94. package/examples/vue/src/components/HelloWorld.vue +40 -0
  95. package/examples/vue/src/components/TheWelcome.vue +86 -0
  96. package/examples/vue/src/components/WelcomeItem.vue +86 -0
  97. package/examples/vue/src/components/icons/IconCommunity.vue +7 -0
  98. package/examples/vue/src/components/icons/IconDocumentation.vue +7 -0
  99. package/examples/vue/src/components/icons/IconEcosystem.vue +7 -0
  100. package/examples/vue/src/components/icons/IconSupport.vue +7 -0
  101. package/examples/vue/src/components/icons/IconTooling.vue +19 -0
  102. package/examples/vue/src/main.ts +6 -0
  103. package/examples/vue/tsconfig.json +16 -0
  104. package/examples/vue/tsconfig.node.json +8 -0
  105. package/examples/vue/vite.config.ts +15 -0
  106. package/flake.nix +1 -1
  107. package/index.d.ts +9 -4
  108. package/index.js +27 -26
  109. package/package.json +19 -20
  110. package/post-build.js +18 -11
  111. package/scripts/gc-node-drop.js +38 -31
  112. package/scripts/gc-rust-drop.js +44 -38
  113. package/trailer.d.ts +9 -4
  114. package/trailer.js +27 -26
  115. package/examples/ngrok-express-quickstart.js +0 -11
  116. package/examples/ngrok-express.js +0 -26
package/index.js CHANGED
@@ -270,9 +270,9 @@ module.exports.NgrokLabeledTunnelBuilder = NgrokLabeledTunnelBuilder
270
270
  // javascript trailer
271
271
  //
272
272
 
273
- const net = require('net');
274
- const fs = require('fs');
275
- const os = require('os');
273
+ const net = require("net");
274
+ const fs = require("fs");
275
+ const os = require("os");
276
276
 
277
277
  // wrap listen with the bind code for passing to net.Server.listen()
278
278
  NgrokHttpTunnelBuilder.prototype._listen = NgrokHttpTunnelBuilder.prototype.listen;
@@ -286,7 +286,7 @@ NgrokTlsTunnelBuilder.prototype.listen = ngrokBind;
286
286
  NgrokLabeledTunnelBuilder.prototype.listen = ngrokBind;
287
287
 
288
288
  // Begin listening for new connections on this tunnel,
289
- // and bind to a local socket so this tunnel can be
289
+ // and bind to a local socket so this tunnel can be
290
290
  // passed into net.Server.listen().
291
291
  async function ngrokBind(bind) {
292
292
  const tunnel = await this._listen();
@@ -303,30 +303,31 @@ async function ngrokBind(bind) {
303
303
  function defineTunnelHandle(tunnel, socket) {
304
304
  // NodeJS net.Server asks passed-in object for 'handle',
305
305
  // Return the native TCP object so the pre-existing socket is used.
306
- Object.defineProperty( tunnel, 'handle', {
307
- get: function() {
306
+ Object.defineProperty(tunnel, "handle", {
307
+ get: function () {
308
308
  // turn on forwarding now that it has been requested
309
- tunnel.forwardTcp('localhost:' + socket.address().port);
309
+ tunnel.forwardTcp("localhost:" + socket.address().port);
310
310
  return socket._handle;
311
- }
311
+ },
312
312
  });
313
313
  }
314
314
 
315
315
  // generate a net.Server listening to a random port
316
316
  async function randomTcpSocket() {
317
- return await asyncListen(new net.Server(), {host:'localhost', port:0});
317
+ return await asyncListen(new net.Server(), { host: "localhost", port: 0 });
318
318
  }
319
319
 
320
320
  // NodeJS has not promisified 'net': https://github.com/nodejs/node/issues/21482
321
321
  function asyncListen(server, options) {
322
322
  return new Promise((resolve, reject) => {
323
323
  const socket = server.listen(options);
324
- socket.once('listening', () => {
325
- resolve(socket);
326
- })
327
- .once('error', (err) => {
328
- reject(err);
329
- });
324
+ socket
325
+ .once("listening", () => {
326
+ resolve(socket);
327
+ })
328
+ .once("error", (err) => {
329
+ reject(err);
330
+ });
330
331
  });
331
332
  }
332
333
 
@@ -378,16 +379,16 @@ async function ngrokListen(server, tunnel) {
378
379
 
379
380
  async function ngrokLinkTcp(tunnel, server) {
380
381
  // random local port
381
- const socket = await asyncListen(server, {host:'localhost', port:0});
382
+ const socket = await asyncListen(server, { host: "localhost", port: 0 });
382
383
  // forward to socket
383
- tunnel.forwardTcp('localhost:' + socket.address().port);
384
+ tunnel.forwardTcp("localhost:" + socket.address().port);
384
385
  return socket;
385
386
  }
386
387
 
387
388
  async function ngrokLinkPipe(tunnel, server) {
388
389
  var proposed = "tun-" + tunnel.id() + ".sock";
389
- if (platform == 'win32') {
390
- proposed = '\\\\.\\pipe\\' + proposed;
390
+ if (platform == "win32") {
391
+ proposed = "\\\\.\\pipe\\" + proposed;
391
392
  }
392
393
  var filename;
393
394
  try {
@@ -405,10 +406,10 @@ async function ngrokLinkPipe(tunnel, server) {
405
406
  }
406
407
 
407
408
  // begin listening
408
- const socket = await asyncListen(server, {path: filename});
409
+ const socket = await asyncListen(server, { path: filename });
409
410
  // tighten permissions
410
411
  try {
411
- if (platform != 'win32') {
412
+ if (platform != "win32") {
412
413
  fs.chmodSync(filename, fs.constants.S_IRWXU);
413
414
  }
414
415
  } catch (err) {
@@ -422,21 +423,21 @@ async function ngrokLinkPipe(tunnel, server) {
422
423
  }
423
424
 
424
425
  function registerCleanup(tunnel, socket) {
425
- process.on('SIGINT', function() {
426
- if (process.listenerCount('SIGINT') > 1) {
426
+ process.on("SIGINT", function () {
427
+ if (process.listenerCount("SIGINT") > 1) {
427
428
  // user has registered a handler, abort this one
428
429
  return;
429
430
  }
430
431
  // close tunnel
431
432
  if (tunnel) {
432
- tunnel.close().then(()=>{
433
- console.debug('ngrok closed tunnel: ' + tunnel.id());
433
+ tunnel.close().then(() => {
434
+ console.debug("ngrok closed tunnel: " + tunnel.id());
434
435
  });
435
436
  }
436
437
  // close webserver's socket
437
438
  if (socket) {
438
439
  socket.close(function () {
439
- console.debug('ngrok closed socket');
440
+ console.debug("ngrok closed socket");
440
441
  });
441
442
  }
442
443
  // unregister any logging callback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrok/ngrok",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -11,7 +11,6 @@
11
11
  "aarch64-linux-android",
12
12
  "aarch64-unknown-linux-gnu",
13
13
  "aarch64-unknown-linux-musl",
14
- "aarch64-pc-windows-msvc",
15
14
  "armv7-unknown-linux-gnueabihf",
16
15
  "x86_64-unknown-linux-musl",
17
16
  "x86_64-unknown-freebsd",
@@ -21,6 +20,7 @@
21
20
  ]
22
21
  }
23
22
  },
23
+ "unused-for-now": "aarch64-pc-windows-msvc",
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
26
  "@napi-rs/cli": "^2.15.1",
@@ -28,10 +28,9 @@
28
28
  "ava": "^4.3.3",
29
29
  "axios": "^1.3.3",
30
30
  "express": "^4.18.2",
31
- "ts-node": "^10.9.1",
31
+ "prettier": "^2.8.7",
32
32
  "typedoc": "^0.23.26",
33
- "typescript": "^4.9.5",
34
- "winston": "^3.8.2"
33
+ "typescript": "^4.9.5"
35
34
  },
36
35
  "ava": {
37
36
  "timeout": "3m"
@@ -44,8 +43,9 @@
44
43
  "build": "napi build --platform --release --js gen.js --dts gen.d.ts --pipe 'node post-build.js trailer index'",
45
44
  "build:debug": "napi build --platform",
46
45
  "clean": "rm -rf node_modules/ target/",
47
- "docs": "mv trailer.d.ts trailer.d.hidden; npx typedoc index.d.ts; mv trailer.d.hidden trailer.d.ts",
46
+ "docs": "mv trailer.d.ts trailer.d.hidden; mv examples .examples; npx typedoc index.d.ts; mv .examples examples; mv trailer.d.hidden trailer.d.ts",
48
47
  "prepublishOnly": "napi prepublish -t npm",
48
+ "prettier": "prettier --write .",
49
49
  "test": "ava",
50
50
  "universal": "napi universal",
51
51
  "version": "napi version"
@@ -54,19 +54,18 @@
54
54
  "description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
55
55
  "repository": "https://github.com/ngrok/ngrok-js",
56
56
  "optionalDependencies": {
57
- "@ngrok/ngrok-win32-x64-msvc": "0.1.1",
58
- "@ngrok/ngrok-darwin-x64": "0.1.1",
59
- "@ngrok/ngrok-linux-x64-gnu": "0.1.1",
60
- "@ngrok/ngrok-darwin-arm64": "0.1.1",
61
- "@ngrok/ngrok-android-arm64": "0.1.1",
62
- "@ngrok/ngrok-linux-arm64-gnu": "0.1.1",
63
- "@ngrok/ngrok-linux-arm64-musl": "0.1.1",
64
- "@ngrok/ngrok-win32-arm64-msvc": "0.1.1",
65
- "@ngrok/ngrok-linux-arm-gnueabihf": "0.1.1",
66
- "@ngrok/ngrok-linux-x64-musl": "0.1.1",
67
- "@ngrok/ngrok-freebsd-x64": "0.1.1",
68
- "@ngrok/ngrok-win32-ia32-msvc": "0.1.1",
69
- "@ngrok/ngrok-android-arm-eabi": "0.1.1",
70
- "@ngrok/ngrok-darwin-universal": "0.1.1"
57
+ "@ngrok/ngrok-win32-x64-msvc": "0.2.0",
58
+ "@ngrok/ngrok-darwin-x64": "0.2.0",
59
+ "@ngrok/ngrok-linux-x64-gnu": "0.2.0",
60
+ "@ngrok/ngrok-darwin-arm64": "0.2.0",
61
+ "@ngrok/ngrok-android-arm64": "0.2.0",
62
+ "@ngrok/ngrok-linux-arm64-gnu": "0.2.0",
63
+ "@ngrok/ngrok-linux-arm64-musl": "0.2.0",
64
+ "@ngrok/ngrok-linux-arm-gnueabihf": "0.2.0",
65
+ "@ngrok/ngrok-linux-x64-musl": "0.2.0",
66
+ "@ngrok/ngrok-freebsd-x64": "0.2.0",
67
+ "@ngrok/ngrok-win32-ia32-msvc": "0.2.0",
68
+ "@ngrok/ngrok-android-arm-eabi": "0.2.0",
69
+ "@ngrok/ngrok-darwin-universal": "0.2.0"
71
70
  }
72
71
  }
package/post-build.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // basically "cat gen.js trailer.js > index.js" but in nodejs to be cross-platform
2
2
  // called from 'yarn build', configured in package.json
3
- // e.g.: node post-build.js trailer index <input_file_path>
3
+ // e.g.: node post-build.js trailer index <input_file_path>
4
4
 
5
5
  var args = process.argv.slice(2);
6
6
  var trailer_prefix = args[0];
@@ -9,7 +9,7 @@ var input_path = args[2];
9
9
 
10
10
  // skipping the typescript file since it actually isn't written before the call to pipe:
11
11
  // https://github.com/napi-rs/napi-rs/issues/1188
12
- if (input_path.endsWith('.d.ts')) {
12
+ if (input_path.endsWith(".d.ts")) {
13
13
  console.log("skipping .d.ts file: " + input_path);
14
14
  return;
15
15
  }
@@ -18,21 +18,28 @@ if (input_path.endsWith('.d.ts')) {
18
18
  concat_files(trailer_prefix, output_prefix, input_path);
19
19
  concat_files(trailer_prefix, output_prefix, input_path.replace(/\.js/, ".d.ts"));
20
20
 
21
- function concat_files (trailer_prefix, output_prefix, input_path) {
22
- console.log("trailer_prefix: '" + trailer_prefix + "' output_prefix: '" + output_prefix
23
- + "' input_path: '" + input_path + "'");
21
+ function concat_files(trailer_prefix, output_prefix, input_path) {
22
+ console.log(
23
+ "trailer_prefix: '" +
24
+ trailer_prefix +
25
+ "' output_prefix: '" +
26
+ output_prefix +
27
+ "' input_path: '" +
28
+ input_path +
29
+ "'"
30
+ );
24
31
  path = require("path");
25
32
  input_filename = path.basename(input_path);
26
- input_suffix = input_filename.substring(input_filename.indexOf('.'), input_filename.length);
33
+ input_suffix = input_filename.substring(input_filename.indexOf("."), input_filename.length);
27
34
  output_filename = output_prefix + input_suffix;
28
35
 
29
36
  console.log("writing: " + output_filename);
30
- var fs = require('fs');
37
+ var fs = require("fs");
31
38
  // input to output
32
- var data = fs.readFileSync(input_path, 'utf8');
33
- fs.writeFileSync(output_filename, data, {encoding: 'utf8', flag: 'w'});
39
+ var data = fs.readFileSync(input_path, "utf8");
40
+ fs.writeFileSync(output_filename, data, { encoding: "utf8", flag: "w" });
34
41
  // trailer to output
35
- data = fs.readFileSync(trailer_prefix + input_suffix, 'utf8');
36
- fs.writeFileSync(output_filename, data, {encoding: 'utf8', flag: 'a'});
42
+ data = fs.readFileSync(trailer_prefix + input_suffix, "utf8");
43
+ fs.writeFileSync(output_filename, data, { encoding: "utf8", flag: "a" });
37
44
  console.log("post-build complete");
38
45
  }
@@ -1,42 +1,49 @@
1
1
  // run with: node --trace-gc --expose-gc
2
- if (typeof global.gc !== 'function') {
2
+ if (typeof global.gc !== "function") {
3
3
  console.log("must run with '--expose-gc'");
4
4
  process.exit();
5
- };
5
+ }
6
6
 
7
- const SegfaultHandler = require('../node_modules/segfault-handler');
8
- SegfaultHandler.registerHandler('crash.log');
7
+ const SegfaultHandler = require("../node_modules/segfault-handler");
8
+ SegfaultHandler.registerHandler("crash.log");
9
9
 
10
- const http = require('http');
11
- http.createServer(
12
- function(req,res){res.writeHead(200);
13
- res.write('Hello');
14
- res.end();
15
- } ).listen(8081);
10
+ const http = require("http");
11
+ http
12
+ .createServer(function (req, res) {
13
+ res.writeHead(200);
14
+ res.write("Hello");
15
+ res.end();
16
+ })
17
+ .listen(8081);
16
18
 
17
- var ngrok = require('..');
19
+ var ngrok = require("..");
18
20
  // turn on debug
19
21
  ngrok.consoleLog();
20
22
 
21
- new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect().then((session) => {
22
- session.httpEndpoint().listen().then((tunnel) => {
23
- tunnel.forwardTcp('localhost:8081').await;
24
- console.log("tunnel: " + tunnel.url() + " id: " + tunnel.id());
25
- setTimeout(function () {
26
- console.log('\n\n=====> running gc');
27
- global.gc();
28
- }, 2000);
23
+ new ngrok.NgrokSessionBuilder()
24
+ .authtokenFromEnv()
25
+ .connect()
26
+ .then((session) => {
27
+ session
28
+ .httpEndpoint()
29
+ .listen()
30
+ .then((tunnel) => {
31
+ tunnel.forwardTcp("localhost:8081").await;
32
+ console.log("tunnel: " + tunnel.url() + " id: " + tunnel.id());
33
+ setTimeout(function () {
34
+ console.log("\n\n=====> running gc");
35
+ global.gc();
36
+ }, 2000);
29
37
 
30
- setTimeout(function () {
31
- console.log('\n\n=====> closing and nulling tunnel');
32
- tunnel.close().await;
33
- tunnel = null;
34
- }, 4000);
38
+ setTimeout(function () {
39
+ console.log("\n\n=====> closing and nulling tunnel");
40
+ tunnel.close().await;
41
+ tunnel = null;
42
+ }, 4000);
35
43
 
36
- setTimeout(function () {
37
- console.log('\n\n=====> running gc');
38
- global.gc();
39
- }, 6000);
40
-
41
- });
42
- }).await;
44
+ setTimeout(function () {
45
+ console.log("\n\n=====> running gc");
46
+ global.gc();
47
+ }, 6000);
48
+ });
49
+ }).await;
@@ -1,47 +1,53 @@
1
1
  // run with: node --trace-gc --expose-gc
2
- if (typeof global.gc !== 'function') {
2
+ if (typeof global.gc !== "function") {
3
3
  console.log("must run with '--expose-gc'");
4
4
  process.exit();
5
- };
5
+ }
6
6
 
7
- const SegfaultHandler = require('../node_modules/segfault-handler');
8
- SegfaultHandler.registerHandler('crash.log');
7
+ const SegfaultHandler = require("../node_modules/segfault-handler");
8
+ SegfaultHandler.registerHandler("crash.log");
9
9
 
10
- const http = require('http');
11
- http.createServer(
12
- function(req,res){res.writeHead(200);
13
- res.write('Hello');
14
- res.end();
15
- } ).listen(8081);
10
+ const http = require("http");
11
+ http
12
+ .createServer(function (req, res) {
13
+ res.writeHead(200);
14
+ res.write("Hello");
15
+ res.end();
16
+ })
17
+ .listen(8081);
16
18
 
17
- var ngrok = require('..');
19
+ var ngrok = require("..");
18
20
  // turn on debug
19
21
  ngrok.consoleLog();
20
22
 
21
- new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect().then((session) => {
22
- session.httpEndpoint().listen().then((tunnel) => {
23
- tunnel.forwardTcp('localhost:8081').await;
24
- const tun_id = tunnel.id();
25
- console.log("tunnel: " + tunnel.url() + " id: " + tun_id);
26
- console.log('\n\n=====> nulling tunnel');
27
- tunnel = null; // nodejs can gc
28
-
29
- setTimeout(function () {
30
- console.log('\n\n=====> running gc');
31
- global.gc();
32
- }, 2000);
33
-
34
- setTimeout(function () {
35
- console.log('\n\n=====> closing tunnel');
36
- session.closeTunnel(tun_id).await;
37
- }, 4000);
38
-
39
- setTimeout(function () {
40
- console.log('\n\n=====> nulling session, running gc');
41
- session = null;
42
- global.gc();
43
- }, 6000);
44
-
45
- });
46
- }).await;
47
-
23
+ new ngrok.NgrokSessionBuilder()
24
+ .authtokenFromEnv()
25
+ .connect()
26
+ .then((session) => {
27
+ session
28
+ .httpEndpoint()
29
+ .listen()
30
+ .then((tunnel) => {
31
+ tunnel.forwardTcp("localhost:8081").await;
32
+ const tun_id = tunnel.id();
33
+ console.log("tunnel: " + tunnel.url() + " id: " + tun_id);
34
+ console.log("\n\n=====> nulling tunnel");
35
+ tunnel = null; // nodejs can gc
36
+
37
+ setTimeout(function () {
38
+ console.log("\n\n=====> running gc");
39
+ global.gc();
40
+ }, 2000);
41
+
42
+ setTimeout(function () {
43
+ console.log("\n\n=====> closing tunnel");
44
+ session.closeTunnel(tun_id).await;
45
+ }, 4000);
46
+
47
+ setTimeout(function () {
48
+ console.log("\n\n=====> nulling session, running gc");
49
+ session = null;
50
+ global.gc();
51
+ }, 6000);
52
+ });
53
+ }).await;
package/trailer.d.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  /** Generate, or convert a given tunnel, into one that can be passed into net.Server.listen(). */
2
- export function listenable(tunnel?: (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)): (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)
2
+ export function listenable(
3
+ tunnel?: NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel
4
+ ): NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel;
3
5
  /** Start the given net.Server listening to a generated, or passed in, tunnel. */
4
- export function listen(server: import("net").Server, tunnel?: (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)): (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)
5
- /**
6
+ export function listen(
7
+ server: import("net").Server,
8
+ tunnel?: NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel
9
+ ): NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel;
10
+ /**
6
11
  * Register a console.log callback for ngrok INFO logging.
7
12
  * Optionally set the logging level to one of ERROR, WARN, INFO, DEBUG, or TRACE.
8
13
  */
9
- export function consoleLog(level?: String)
14
+ export function consoleLog(level?: String);
package/trailer.js CHANGED
@@ -2,9 +2,9 @@
2
2
  // javascript trailer
3
3
  //
4
4
 
5
- const net = require('net');
6
- const fs = require('fs');
7
- const os = require('os');
5
+ const net = require("net");
6
+ const fs = require("fs");
7
+ const os = require("os");
8
8
 
9
9
  // wrap listen with the bind code for passing to net.Server.listen()
10
10
  NgrokHttpTunnelBuilder.prototype._listen = NgrokHttpTunnelBuilder.prototype.listen;
@@ -18,7 +18,7 @@ NgrokTlsTunnelBuilder.prototype.listen = ngrokBind;
18
18
  NgrokLabeledTunnelBuilder.prototype.listen = ngrokBind;
19
19
 
20
20
  // Begin listening for new connections on this tunnel,
21
- // and bind to a local socket so this tunnel can be
21
+ // and bind to a local socket so this tunnel can be
22
22
  // passed into net.Server.listen().
23
23
  async function ngrokBind(bind) {
24
24
  const tunnel = await this._listen();
@@ -35,30 +35,31 @@ async function ngrokBind(bind) {
35
35
  function defineTunnelHandle(tunnel, socket) {
36
36
  // NodeJS net.Server asks passed-in object for 'handle',
37
37
  // Return the native TCP object so the pre-existing socket is used.
38
- Object.defineProperty( tunnel, 'handle', {
39
- get: function() {
38
+ Object.defineProperty(tunnel, "handle", {
39
+ get: function () {
40
40
  // turn on forwarding now that it has been requested
41
- tunnel.forwardTcp('localhost:' + socket.address().port);
41
+ tunnel.forwardTcp("localhost:" + socket.address().port);
42
42
  return socket._handle;
43
- }
43
+ },
44
44
  });
45
45
  }
46
46
 
47
47
  // generate a net.Server listening to a random port
48
48
  async function randomTcpSocket() {
49
- return await asyncListen(new net.Server(), {host:'localhost', port:0});
49
+ return await asyncListen(new net.Server(), { host: "localhost", port: 0 });
50
50
  }
51
51
 
52
52
  // NodeJS has not promisified 'net': https://github.com/nodejs/node/issues/21482
53
53
  function asyncListen(server, options) {
54
54
  return new Promise((resolve, reject) => {
55
55
  const socket = server.listen(options);
56
- socket.once('listening', () => {
57
- resolve(socket);
58
- })
59
- .once('error', (err) => {
60
- reject(err);
61
- });
56
+ socket
57
+ .once("listening", () => {
58
+ resolve(socket);
59
+ })
60
+ .once("error", (err) => {
61
+ reject(err);
62
+ });
62
63
  });
63
64
  }
64
65
 
@@ -110,16 +111,16 @@ async function ngrokListen(server, tunnel) {
110
111
 
111
112
  async function ngrokLinkTcp(tunnel, server) {
112
113
  // random local port
113
- const socket = await asyncListen(server, {host:'localhost', port:0});
114
+ const socket = await asyncListen(server, { host: "localhost", port: 0 });
114
115
  // forward to socket
115
- tunnel.forwardTcp('localhost:' + socket.address().port);
116
+ tunnel.forwardTcp("localhost:" + socket.address().port);
116
117
  return socket;
117
118
  }
118
119
 
119
120
  async function ngrokLinkPipe(tunnel, server) {
120
121
  var proposed = "tun-" + tunnel.id() + ".sock";
121
- if (platform == 'win32') {
122
- proposed = '\\\\.\\pipe\\' + proposed;
122
+ if (platform == "win32") {
123
+ proposed = "\\\\.\\pipe\\" + proposed;
123
124
  }
124
125
  var filename;
125
126
  try {
@@ -137,10 +138,10 @@ async function ngrokLinkPipe(tunnel, server) {
137
138
  }
138
139
 
139
140
  // begin listening
140
- const socket = await asyncListen(server, {path: filename});
141
+ const socket = await asyncListen(server, { path: filename });
141
142
  // tighten permissions
142
143
  try {
143
- if (platform != 'win32') {
144
+ if (platform != "win32") {
144
145
  fs.chmodSync(filename, fs.constants.S_IRWXU);
145
146
  }
146
147
  } catch (err) {
@@ -154,21 +155,21 @@ async function ngrokLinkPipe(tunnel, server) {
154
155
  }
155
156
 
156
157
  function registerCleanup(tunnel, socket) {
157
- process.on('SIGINT', function() {
158
- if (process.listenerCount('SIGINT') > 1) {
158
+ process.on("SIGINT", function () {
159
+ if (process.listenerCount("SIGINT") > 1) {
159
160
  // user has registered a handler, abort this one
160
161
  return;
161
162
  }
162
163
  // close tunnel
163
164
  if (tunnel) {
164
- tunnel.close().then(()=>{
165
- console.debug('ngrok closed tunnel: ' + tunnel.id());
165
+ tunnel.close().then(() => {
166
+ console.debug("ngrok closed tunnel: " + tunnel.id());
166
167
  });
167
168
  }
168
169
  // close webserver's socket
169
170
  if (socket) {
170
171
  socket.close(function () {
171
- console.debug('ngrok closed socket');
172
+ console.debug("ngrok closed socket");
172
173
  });
173
174
  }
174
175
  // unregister any logging callback
@@ -1,11 +0,0 @@
1
- const express = require('express')
2
- const ngrok = require('@ngrok/ngrok')
3
- const app = express()
4
-
5
- app.get('/', (req, res) => {
6
- res.send('Hello World!')
7
- })
8
-
9
- ngrok.listen(app).then(() => {
10
- console.log("established tunnel at: " + app.tunnel.url());
11
- });
@@ -1,26 +0,0 @@
1
- const express = require('express')
2
- const ngrok = require('@ngrok/ngrok')
3
- const app = express()
4
-
5
- app.get('/', (req, res) => {
6
- res.send('Hello World!')
7
- })
8
-
9
- async function setup() {
10
- // create session
11
- const session = await new ngrok.NgrokSessionBuilder()
12
- .authtokenFromEnv()
13
- .metadata("Online in One Line")
14
- .connect();
15
- // create tunnel
16
- const tunnel = await session.httpEndpoint()
17
- .allowCidr("0.0.0.0/0")
18
- .oauth("google")
19
- .requestHeader("X-Req-Yup", "true")
20
- .listen();
21
- console.log("tunnel established at: " + tunnel.url());
22
- // link tunnel to app
23
- ngrok.listen(app, tunnel)
24
- }
25
-
26
- setup();