@ngrok/ngrok 0.1.1 → 0.3.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.
- package/.prettierrc.json +3 -0
- package/CHANGELOG.md +10 -0
- package/Cargo.toml +1 -1
- package/README.md +51 -10
- package/RELEASE.md +3 -3
- package/docs/assets/highlight.css +13 -6
- package/docs/assets/main.js +3 -3
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +447 -362
- package/docs/classes/NgrokHttpTunnel.html +112 -77
- package/docs/classes/NgrokHttpTunnelBuilder.html +235 -199
- package/docs/classes/NgrokLabeledTunnel.html +107 -72
- package/docs/classes/NgrokLabeledTunnelBuilder.html +84 -49
- package/docs/classes/NgrokSession.html +99 -66
- package/docs/classes/NgrokSessionBuilder.html +171 -138
- package/docs/classes/NgrokTcpTunnel.html +112 -77
- package/docs/classes/NgrokTcpTunnelBuilder.html +115 -80
- package/docs/classes/NgrokTlsTunnel.html +112 -77
- package/docs/classes/NgrokTlsTunnelBuilder.html +133 -98
- package/docs/classes/UpdateRequest.html +69 -33
- package/docs/functions/authtoken.html +88 -0
- package/docs/functions/connect.html +88 -0
- package/docs/functions/consoleLog.html +50 -34
- package/docs/functions/disconnect.html +88 -0
- package/docs/functions/kill.html +83 -0
- package/docs/functions/listen.html +52 -36
- package/docs/functions/listenable.html +51 -35
- package/docs/functions/loggingCallback.html +56 -40
- package/docs/index.html +115 -84
- package/docs/interfaces/Config.html +608 -0
- package/docs/modules.html +74 -47
- package/examples/express/ngrok-express-quickstart.js +11 -0
- package/examples/express/ngrok-express.js +28 -0
- package/examples/express/package.json +7 -0
- package/examples/fastify/ngrok-fastify.js +26 -0
- package/examples/fastify/package.json +7 -0
- package/examples/hapi/ngrok-hapi.js +35 -0
- package/examples/hapi/package.json +7 -0
- package/examples/koa/ngrok-koa.js +12 -0
- package/examples/koa/package.json +7 -0
- package/examples/nestjs/.eslintrc.js +25 -0
- package/examples/nestjs/.prettierrc +4 -0
- package/examples/nestjs/README.md +73 -0
- package/examples/nestjs/nest-cli.json +8 -0
- package/examples/nestjs/package-lock.json +12138 -0
- package/examples/nestjs/package.json +70 -0
- package/examples/nestjs/src/app.controller.spec.ts +22 -0
- package/examples/nestjs/src/app.controller.ts +12 -0
- package/examples/nestjs/src/app.module.ts +10 -0
- package/examples/nestjs/src/app.service.ts +8 -0
- package/examples/nestjs/src/main.ts +17 -0
- package/examples/nestjs/test/app.e2e-spec.ts +24 -0
- package/examples/nestjs/test/jest-e2e.json +9 -0
- package/examples/nestjs/tsconfig.build.json +4 -0
- package/examples/nestjs/tsconfig.json +21 -0
- package/examples/nextjs/next.config.js +12 -0
- package/examples/nextjs/ngrok.config.js +23 -0
- package/examples/nextjs/package.json +6 -0
- package/examples/nextjs/pages/index.js +5 -0
- package/examples/ngrok-connect-full.js +64 -0
- package/examples/ngrok-connect-minimal.js +16 -0
- package/examples/ngrok-http-full.js +28 -22
- package/examples/ngrok-http-minimum.js +17 -13
- package/examples/ngrok-labeled.js +22 -18
- package/examples/ngrok-listen.js +6 -7
- package/examples/ngrok-tcp.js +22 -19
- package/examples/ngrok-tls.js +23 -20
- package/examples/ngrok-typescript.ts +32 -27
- package/examples/ngrok-windows-pipe.js +22 -14
- package/examples/ngrok-winston.js +9 -9
- package/examples/package.json +11 -0
- package/examples/remix/.eslintrc.js +4 -0
- package/examples/remix/README.md +53 -0
- package/examples/remix/app/entry.client.tsx +18 -0
- package/examples/remix/app/entry.server.tsx +101 -0
- package/examples/remix/app/root.tsx +20 -0
- package/examples/remix/app/routes/_index.tsx +30 -0
- package/examples/remix/ngrok.config.js +16 -0
- package/examples/remix/package.json +30 -0
- package/examples/remix/public/favicon.ico +0 -0
- package/examples/remix/remix.config.js +16 -0
- package/examples/remix/remix.env.d.ts +2 -0
- package/examples/remix/tsconfig.json +22 -0
- package/examples/svelte/README.md +38 -0
- package/examples/svelte/jsconfig.json +17 -0
- package/examples/svelte/ngrok.config.cjs +18 -0
- package/examples/svelte/package.json +22 -0
- package/examples/svelte/src/app.d.ts +12 -0
- package/examples/svelte/src/app.html +12 -0
- package/examples/svelte/src/routes/+page.svelte +2 -0
- package/examples/svelte/static/favicon.png +0 -0
- package/examples/svelte/svelte.config.js +14 -0
- package/examples/svelte/vite.config.js +6 -0
- package/examples/vue/.vscode/extensions.json +3 -0
- package/examples/vue/README.md +40 -0
- package/examples/vue/env.d.ts +1 -0
- package/examples/vue/index.html +13 -0
- package/examples/vue/ngrok.config.ts +18 -0
- package/examples/vue/package.json +25 -0
- package/examples/vue/public/favicon.ico +0 -0
- package/examples/vue/src/App.vue +47 -0
- package/examples/vue/src/assets/base.css +74 -0
- package/examples/vue/src/assets/logo.svg +1 -0
- package/examples/vue/src/assets/main.css +35 -0
- package/examples/vue/src/components/HelloWorld.vue +40 -0
- package/examples/vue/src/components/TheWelcome.vue +86 -0
- package/examples/vue/src/components/WelcomeItem.vue +86 -0
- package/examples/vue/src/components/icons/IconCommunity.vue +7 -0
- package/examples/vue/src/components/icons/IconDocumentation.vue +7 -0
- package/examples/vue/src/components/icons/IconEcosystem.vue +7 -0
- package/examples/vue/src/components/icons/IconSupport.vue +7 -0
- package/examples/vue/src/components/icons/IconTooling.vue +19 -0
- package/examples/vue/src/main.ts +6 -0
- package/examples/vue/tsconfig.json +16 -0
- package/examples/vue/tsconfig.node.json +8 -0
- package/examples/vue/vite.config.ts +15 -0
- package/flake.nix +1 -1
- package/index.d.ts +243 -19
- package/index.js +145 -29
- package/package.json +20 -21
- package/post-build.js +18 -11
- package/scripts/gc-node-drop.js +38 -31
- package/scripts/gc-rust-drop.js +44 -38
- package/src/config.rs +182 -0
- package/src/connect.rs +328 -0
- package/src/http.rs +5 -4
- package/src/lib.rs +2 -0
- package/src/session.rs +61 -4
- package/src/tls.rs +1 -1
- package/src/tunnel.rs +105 -37
- package/src/tunnel_builder.rs +8 -0
- package/trailer.d.ts +9 -4
- package/trailer.js +140 -28
- package/examples/ngrok-express-quickstart.js +0 -11
- package/examples/ngrok-express.js +0 -26
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nestjs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "",
|
|
6
|
+
"private": true,
|
|
7
|
+
"license": "UNLICENSED",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "nest build",
|
|
10
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
11
|
+
"start": "nest start",
|
|
12
|
+
"start:dev": "nest start --watch",
|
|
13
|
+
"start:debug": "nest start --debug --watch",
|
|
14
|
+
"start:prod": "node dist/main",
|
|
15
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"test:watch": "jest --watch",
|
|
18
|
+
"test:cov": "jest --coverage",
|
|
19
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
20
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@nestjs/common": "^9.0.0",
|
|
24
|
+
"@nestjs/core": "^9.0.0",
|
|
25
|
+
"@nestjs/platform-express": "^9.0.0",
|
|
26
|
+
"@ngrok/ngrok": "^0.2.0",
|
|
27
|
+
"reflect-metadata": "^0.1.13",
|
|
28
|
+
"rxjs": "^7.2.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@nestjs/cli": "^9.0.0",
|
|
32
|
+
"@nestjs/schematics": "^9.0.0",
|
|
33
|
+
"@nestjs/testing": "^9.0.0",
|
|
34
|
+
"@types/express": "^4.17.13",
|
|
35
|
+
"@types/jest": "29.5.0",
|
|
36
|
+
"@types/node": "18.15.11",
|
|
37
|
+
"@types/supertest": "^2.0.11",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
40
|
+
"eslint": "^8.0.1",
|
|
41
|
+
"eslint-config-prettier": "^8.3.0",
|
|
42
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
43
|
+
"jest": "29.5.0",
|
|
44
|
+
"prettier": "^2.3.2",
|
|
45
|
+
"source-map-support": "^0.5.20",
|
|
46
|
+
"supertest": "^6.1.3",
|
|
47
|
+
"ts-jest": "29.0.5",
|
|
48
|
+
"ts-loader": "^9.2.3",
|
|
49
|
+
"ts-node": "^10.0.0",
|
|
50
|
+
"tsconfig-paths": "4.2.0",
|
|
51
|
+
"typescript": "^4.7.4"
|
|
52
|
+
},
|
|
53
|
+
"jest": {
|
|
54
|
+
"moduleFileExtensions": [
|
|
55
|
+
"js",
|
|
56
|
+
"json",
|
|
57
|
+
"ts"
|
|
58
|
+
],
|
|
59
|
+
"rootDir": "src",
|
|
60
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
61
|
+
"transform": {
|
|
62
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
63
|
+
},
|
|
64
|
+
"collectCoverageFrom": [
|
|
65
|
+
"**/*.(t|j)s"
|
|
66
|
+
],
|
|
67
|
+
"coverageDirectory": "../coverage",
|
|
68
|
+
"testEnvironment": "node"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { AppController } from './app.controller';
|
|
3
|
+
import { AppService } from './app.service';
|
|
4
|
+
|
|
5
|
+
describe('AppController', () => {
|
|
6
|
+
let appController: AppController;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
const app: TestingModule = await Test.createTestingModule({
|
|
10
|
+
controllers: [AppController],
|
|
11
|
+
providers: [AppService],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
appController = app.get<AppController>(AppController);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('root', () => {
|
|
18
|
+
it('should return "Hello World!"', () => {
|
|
19
|
+
expect(appController.getHello()).toBe('Hello World!');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Controller, Get } from '@nestjs/common';
|
|
2
|
+
import { AppService } from './app.service';
|
|
3
|
+
|
|
4
|
+
@Controller()
|
|
5
|
+
export class AppController {
|
|
6
|
+
constructor(private readonly appService: AppService) {}
|
|
7
|
+
|
|
8
|
+
@Get()
|
|
9
|
+
getHello(): string {
|
|
10
|
+
return this.appService.getHello();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NestFactory } from '@nestjs/core';
|
|
2
|
+
import { Logger } from '@nestjs/common';
|
|
3
|
+
import { AppModule } from './app.module';
|
|
4
|
+
import { NgrokSessionBuilder } from '@ngrok/ngrok';
|
|
5
|
+
|
|
6
|
+
async function bootstrap() {
|
|
7
|
+
const port = 3000;
|
|
8
|
+
const app = await NestFactory.create(AppModule);
|
|
9
|
+
await app.listen(port);
|
|
10
|
+
|
|
11
|
+
// Setup ngrok ingress
|
|
12
|
+
const session = await new NgrokSessionBuilder().authtokenFromEnv().connect();
|
|
13
|
+
const tunnel = await session.httpEndpoint().listen();
|
|
14
|
+
new Logger('main').log(`Ingress established at ${tunnel.url()}`);
|
|
15
|
+
tunnel.forwardTcp(`localhost:${port}`);
|
|
16
|
+
}
|
|
17
|
+
bootstrap();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { INestApplication } from '@nestjs/common';
|
|
3
|
+
import * as request from 'supertest';
|
|
4
|
+
import { AppModule } from './../src/app.module';
|
|
5
|
+
|
|
6
|
+
describe('AppController (e2e)', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
11
|
+
imports: [AppModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = moduleFixture.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('/ (GET)', () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.get('/')
|
|
21
|
+
.expect(200)
|
|
22
|
+
.expect('Hello World!');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "es2017",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"strictNullChecks": false,
|
|
16
|
+
"noImplicitAny": false,
|
|
17
|
+
"strictBindCallApply": false,
|
|
18
|
+
"forceConsistentCasingInFileNames": false,
|
|
19
|
+
"noFallthroughCasesInSwitch": false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const ngrok = require("@ngrok/ngrok");
|
|
2
|
+
|
|
3
|
+
// setup ngrok ingress in the parent process
|
|
4
|
+
var makeTunnel = true;
|
|
5
|
+
var host = "localhost";
|
|
6
|
+
var port = process.env.PORT || "3000";
|
|
7
|
+
|
|
8
|
+
process.argv.forEach((item, index) => {
|
|
9
|
+
// The first process to configure is a child which runs building, then the parent
|
|
10
|
+
// configures later, so use arguments rather than environment variable to run once.
|
|
11
|
+
if (item.includes("processChild")) makeTunnel = false;
|
|
12
|
+
if (["--hostname", "-H"].includes(item)) host = process.argv[index + 1];
|
|
13
|
+
if (["--port", "-p"].includes(item)) port = process.argv[index + 1];
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
async function setup() {
|
|
17
|
+
const session = await new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect();
|
|
18
|
+
const tunnel = await session.httpEndpoint().listen();
|
|
19
|
+
console.log(`Forwarding to: ${host}:${port} from ingress at: ${tunnel.url()}`);
|
|
20
|
+
tunnel.forwardTcp(`${host}:${port}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (makeTunnel) setup();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
6
|
+
|
|
7
|
+
// make webserver
|
|
8
|
+
const http = require("http");
|
|
9
|
+
http
|
|
10
|
+
.createServer(function (req, res) {
|
|
11
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
12
|
+
res.write("Congrats you have a created an ngrok web server");
|
|
13
|
+
res.end();
|
|
14
|
+
})
|
|
15
|
+
.listen(UNIX_SOCKET); // Server object listens on unix socket
|
|
16
|
+
console.log(`Node.js web server at ${UNIX_SOCKET} is running..`);
|
|
17
|
+
|
|
18
|
+
// setup ngrok
|
|
19
|
+
const ngrok = require("@ngrok/ngrok");
|
|
20
|
+
ngrok.consoleLog("INFO"); // turn on info logging
|
|
21
|
+
|
|
22
|
+
ngrok
|
|
23
|
+
.connect({
|
|
24
|
+
// session configuration
|
|
25
|
+
addr: `pipe:${UNIX_SOCKET}`,
|
|
26
|
+
// addr: `localhost:8080`,
|
|
27
|
+
// authtoken: "<authtoken>",
|
|
28
|
+
authtoken_from_env: true,
|
|
29
|
+
on_status_change: (addr, error) => {
|
|
30
|
+
console.log(`disconnected, addr ${addr} error: ${error}`);
|
|
31
|
+
},
|
|
32
|
+
session_metadata: "Online in One Line",
|
|
33
|
+
// tunnel configuration
|
|
34
|
+
basic_auth: ["ngrok:online1line"],
|
|
35
|
+
circuit_breaker: 0.1,
|
|
36
|
+
compression: true,
|
|
37
|
+
// domain: "<domain>",
|
|
38
|
+
"ip_restriction.allow_cidrs": ["0.0.0.0/0"],
|
|
39
|
+
"ip_restriction.deny_cidrs": ["10.1.1.1/32"],
|
|
40
|
+
metadata: "example tunnel metadata from nodejs",
|
|
41
|
+
// mutual_tls_cas: [fs.readFileSync('ca.crt', 'utf8')],
|
|
42
|
+
// "oauth.provider": "google",
|
|
43
|
+
// "oauth.allow_domains": ["<domain>"],
|
|
44
|
+
// "oauth.allow_emails": ["<email>"],
|
|
45
|
+
// "oauth.scopes": ["<scope>"],
|
|
46
|
+
// "oidc.issuer_url": "<url>",
|
|
47
|
+
// "oidc.client_id": "<id>",
|
|
48
|
+
// "oidc.client_secret": "<secret>",
|
|
49
|
+
// "oidc.allow_domains": ["<domain>"],
|
|
50
|
+
// "oidc.allow_emails": ["<email>"],
|
|
51
|
+
// "oidc.scopes": ["<scope>"],
|
|
52
|
+
proxy_proto: "", // One of: "", "1", "2"
|
|
53
|
+
"request_header.remove": ["X-Req-Nope"],
|
|
54
|
+
"response_header.remove": ["X-Res-Nope"],
|
|
55
|
+
"request_header.add": ["X-Req-Yup:true"],
|
|
56
|
+
"response_header.add": ["X-Res-Yup:true"],
|
|
57
|
+
schemes: ["HTTPS"],
|
|
58
|
+
// "verify_webhook.provider": "twilio",
|
|
59
|
+
// "verify_webhook.secret": "asdf",
|
|
60
|
+
// websocket_tcp_converter: true,
|
|
61
|
+
})
|
|
62
|
+
.then((url) => {
|
|
63
|
+
console.log(`Ingress established at: ${url}`);
|
|
64
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// make webserver
|
|
2
|
+
const http = require("http");
|
|
3
|
+
http
|
|
4
|
+
.createServer(function (req, res) {
|
|
5
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
6
|
+
res.write("Congrats you have a created an ngrok web server");
|
|
7
|
+
res.end();
|
|
8
|
+
})
|
|
9
|
+
.listen(8080);
|
|
10
|
+
console.log(`Node.js web server at 8080 is running..`);
|
|
11
|
+
|
|
12
|
+
// setup ngrok
|
|
13
|
+
const ngrok = require("@ngrok/ngrok");
|
|
14
|
+
ngrok.connect({ addr: 8080, authtoken_from_env: true }).then((url) => {
|
|
15
|
+
console.log(`Ingress established at: ${url}`);
|
|
16
|
+
});
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
1
|
+
const UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const http = require("http");
|
|
9
|
+
http
|
|
10
|
+
.createServer(function (req, res) {
|
|
11
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
12
|
+
res.write("Congrats you have a created an ngrok web server");
|
|
13
|
+
res.end();
|
|
14
|
+
})
|
|
15
|
+
.listen(UNIX_SOCKET); // Server object listens on unix socket
|
|
16
|
+
console.log("Node.js web server at", UNIX_SOCKET, "is running..");
|
|
14
17
|
|
|
15
18
|
// setup ngrok
|
|
16
|
-
|
|
19
|
+
const ngrok = require("@ngrok/ngrok");
|
|
17
20
|
// import ngrok from '@ngrok/ngrok' // if inside a module
|
|
18
|
-
ngrok.consoleLog(
|
|
21
|
+
ngrok.consoleLog("INFO"); // turn on info logging
|
|
19
22
|
|
|
20
23
|
builder = new ngrok.NgrokSessionBuilder();
|
|
21
24
|
builder
|
|
@@ -31,19 +34,21 @@ builder
|
|
|
31
34
|
console.log("restart command");
|
|
32
35
|
})
|
|
33
36
|
.handleUpdateCommand((update) => {
|
|
34
|
-
console.log(
|
|
35
|
-
|
|
37
|
+
console.log(
|
|
38
|
+
"update command, version:", update.version,
|
|
39
|
+
"permitMajorVersion:", update.permitMajorVersion
|
|
40
|
+
);
|
|
36
41
|
})
|
|
37
42
|
.handleHeartbeat((latency) => {
|
|
38
|
-
console.log("heartbeat, latency:
|
|
43
|
+
console.log("heartbeat, latency:", latency, "milliseconds");
|
|
39
44
|
})
|
|
40
45
|
.handleDisconnection((addr, error) => {
|
|
41
|
-
console.log("disconnected, addr: "
|
|
42
|
-
+ " error: " + error);
|
|
46
|
+
console.log("disconnected, addr:", addr, "error:", error);
|
|
43
47
|
});
|
|
44
48
|
|
|
45
49
|
builder.connect().then((session) => {
|
|
46
|
-
session
|
|
50
|
+
session
|
|
51
|
+
.httpEndpoint()
|
|
47
52
|
// .allowCidr("0.0.0.0/0")
|
|
48
53
|
// .basicAuth("ngrok", "online1line")
|
|
49
54
|
// .circuitBreaker(0.5)
|
|
@@ -62,8 +67,9 @@ builder.connect().then((session) => {
|
|
|
62
67
|
// .websocketTcpConversion()
|
|
63
68
|
// .webhookVerification("twilio", "asdf")
|
|
64
69
|
.metadata("example tunnel metadata from nodejs")
|
|
65
|
-
.listen()
|
|
66
|
-
|
|
70
|
+
.listen()
|
|
71
|
+
.then((tunnel) => {
|
|
72
|
+
console.log("Ingress established at:", tunnel.url());
|
|
67
73
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
68
|
-
|
|
74
|
+
});
|
|
69
75
|
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
const http = require(
|
|
2
|
-
http
|
|
3
|
-
function(req,res){
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var ngrok = require('@ngrok/ngrok');
|
|
9
|
-
new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect().then((session) => {
|
|
10
|
-
session.httpEndpoint().listen().then((tunnel) => {
|
|
11
|
-
console.log('tunnel at: ' + tunnel.url());
|
|
12
|
-
tunnel.forwardTcp('localhost:8081');
|
|
1
|
+
const http = require("http");
|
|
2
|
+
http
|
|
3
|
+
.createServer(function (req, res) {
|
|
4
|
+
res.writeHead(200);
|
|
5
|
+
res.write("Hello");
|
|
6
|
+
res.end();
|
|
13
7
|
})
|
|
14
|
-
|
|
8
|
+
.listen(8081);
|
|
9
|
+
|
|
10
|
+
var ngrok = require("@ngrok/ngrok");
|
|
11
|
+
|
|
12
|
+
async function create_tunnel() {
|
|
13
|
+
const session = await new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect();
|
|
14
|
+
const tunnel = await session.httpEndpoint().listen();
|
|
15
|
+
console.log("Ingress established at:", tunnel.url());
|
|
16
|
+
tunnel.forwardTcp("localhost:8081");
|
|
17
|
+
}
|
|
18
|
+
create_tunnel();
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
1
|
+
const UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const http = require("http");
|
|
9
|
+
http
|
|
10
|
+
.createServer(function (req, res) {
|
|
11
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
12
|
+
res.write("Congrats you have a created an ngrok web server");
|
|
13
|
+
res.end();
|
|
14
|
+
})
|
|
15
|
+
.listen(UNIX_SOCKET); // Server object listens on unix socket
|
|
16
|
+
console.log("Node.js web server at", UNIX_SOCKET, "is running..");
|
|
14
17
|
|
|
15
18
|
// setup ngrok
|
|
16
|
-
|
|
19
|
+
const ngrok = require("@ngrok/ngrok");
|
|
17
20
|
builder = new ngrok.NgrokSessionBuilder();
|
|
18
|
-
builder.authtokenFromEnv()
|
|
19
|
-
.metadata("Online in One Line");
|
|
21
|
+
builder.authtokenFromEnv().metadata("Online in One Line");
|
|
20
22
|
|
|
21
23
|
builder.connect().then((session) => {
|
|
22
|
-
session
|
|
24
|
+
session
|
|
25
|
+
.labeledTunnel()
|
|
23
26
|
.label("edge", "edghts_<edge_id>")
|
|
24
27
|
.metadata("example tunnel metadata from nodejs")
|
|
25
|
-
.listen()
|
|
26
|
-
|
|
28
|
+
.listen()
|
|
29
|
+
.then((tunnel) => {
|
|
30
|
+
console.log("Ingress established at: " + JSON.stringify(tunnel.labels()));
|
|
27
31
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
28
|
-
|
|
32
|
+
});
|
|
29
33
|
});
|
package/examples/ngrok-listen.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
const server = require(
|
|
2
|
-
|
|
3
|
-
res.write(
|
|
1
|
+
const server = require("http").createServer(function (req, res) {
|
|
2
|
+
res.writeHead(200);
|
|
3
|
+
res.write("Hello");
|
|
4
4
|
res.end();
|
|
5
|
-
}
|
|
5
|
+
});
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const ngrok = require("@ngrok/ngrok");
|
|
8
8
|
|
|
9
9
|
ngrok.listen(server).then(() => {
|
|
10
|
-
console.log("
|
|
10
|
+
console.log("Ingress establised at:", server.tunnel.url());
|
|
11
11
|
});
|
|
12
|
-
|
package/examples/ngrok-tcp.js
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
1
|
+
const UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const http = require("http");
|
|
9
|
+
http
|
|
10
|
+
.createServer(function (req, res) {
|
|
11
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
12
|
+
res.write("Congrats you have a created an ngrok web server");
|
|
13
|
+
res.end();
|
|
14
|
+
})
|
|
15
|
+
.listen(UNIX_SOCKET); // Server object listens on unix socket
|
|
16
|
+
console.log("Node.js web server at", UNIX_SOCKET, "is running..");
|
|
14
17
|
|
|
15
18
|
// setup ngrok
|
|
16
|
-
|
|
19
|
+
const ngrok = require("@ngrok/ngrok");
|
|
17
20
|
builder = new ngrok.NgrokSessionBuilder();
|
|
18
|
-
builder.authtokenFromEnv()
|
|
19
|
-
.metadata("Online in One Line");
|
|
21
|
+
builder.authtokenFromEnv().metadata("Online in One Line");
|
|
20
22
|
|
|
21
|
-
var global_tunnel;
|
|
22
23
|
builder.connect().then((session) => {
|
|
23
|
-
session
|
|
24
|
+
session
|
|
25
|
+
.tcpEndpoint()
|
|
24
26
|
// .allowCidr("0.0.0.0/0")
|
|
25
27
|
// .denyCidr("10.1.1.1/32")
|
|
26
28
|
// .forwardsTo("example nodejs")
|
|
27
29
|
// .proxyProto("") // One of: "", "1", "2"
|
|
28
30
|
// .remoteAddr("<n>.tcp.ngrok.io:<p>")
|
|
29
31
|
.metadata("example tunnel metadata from nodejs")
|
|
30
|
-
.listen()
|
|
31
|
-
|
|
32
|
+
.listen()
|
|
33
|
+
.then((tunnel) => {
|
|
34
|
+
console.log("Ingress established at:", tunnel.url());
|
|
32
35
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
33
|
-
|
|
36
|
+
});
|
|
34
37
|
});
|
package/examples/ngrok-tls.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
1
|
+
const UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const http = require("http");
|
|
9
|
+
http
|
|
10
|
+
.createServer(function (req, res) {
|
|
11
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
12
|
+
res.write("Congrats you have a created an ngrok web server");
|
|
13
|
+
res.end();
|
|
14
|
+
})
|
|
15
|
+
.listen(UNIX_SOCKET); // Server object listens on unix socket
|
|
16
|
+
console.log("Node.js web server at", UNIX_SOCKET, "is running..");
|
|
14
17
|
|
|
15
18
|
// setup ngrok
|
|
16
|
-
|
|
19
|
+
const ngrok = require("@ngrok/ngrok");
|
|
17
20
|
builder = new ngrok.NgrokSessionBuilder();
|
|
18
|
-
builder.authtokenFromEnv()
|
|
19
|
-
.metadata("Online in One Line");
|
|
21
|
+
builder.authtokenFromEnv().metadata("Online in One Line");
|
|
20
22
|
|
|
21
23
|
builder.connect().then((session) => {
|
|
22
24
|
console.log("established session");
|
|
23
|
-
session
|
|
25
|
+
session
|
|
26
|
+
.tlsEndpoint()
|
|
24
27
|
// .allowCidr("0.0.0.0/0")
|
|
25
28
|
// .denyCidr("10.1.1.1/32")
|
|
26
29
|
// .domain("<somedomain>.ngrok.io")
|
|
27
30
|
// .forwardsTo("example nodejs")
|
|
28
31
|
// .mutualTlsca(fs.readFileSync('ca.crt'))
|
|
29
32
|
// .proxyProto("") // One of: "", "1", "2"
|
|
30
|
-
.termination(fs.readFileSync(
|
|
31
|
-
fs.readFileSync('domain.key'))
|
|
33
|
+
.termination(fs.readFileSync("domain.crt"), fs.readFileSync("domain.key"))
|
|
32
34
|
.metadata("example tunnel metadata from nodejs")
|
|
33
|
-
.listen()
|
|
34
|
-
|
|
35
|
+
.listen()
|
|
36
|
+
.then((tunnel) => {
|
|
37
|
+
console.log("Ingress established at:", tunnel.url());
|
|
35
38
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
36
|
-
|
|
39
|
+
});
|
|
37
40
|
});
|