@ngrok/ngrok 0.1.0 → 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.
- package/.prettierrc.json +3 -0
- package/CHANGELOG.md +10 -0
- package/Cargo.toml +2 -2
- package/README.md +35 -1
- package/RELEASE.md +4 -3
- package/docs/assets/style.css +4 -5
- package/docs/classes/NgrokHttpTunnel.html +9 -9
- package/docs/classes/NgrokHttpTunnelBuilder.html +21 -21
- package/docs/classes/NgrokLabeledTunnel.html +8 -8
- package/docs/classes/NgrokLabeledTunnelBuilder.html +4 -4
- package/docs/classes/NgrokSession.html +7 -7
- package/docs/classes/NgrokSessionBuilder.html +15 -15
- package/docs/classes/NgrokTcpTunnel.html +9 -9
- package/docs/classes/NgrokTcpTunnelBuilder.html +8 -8
- package/docs/classes/NgrokTlsTunnel.html +9 -9
- package/docs/classes/NgrokTlsTunnelBuilder.html +10 -10
- package/docs/classes/UpdateRequest.html +3 -3
- package/docs/functions/consoleLog.html +1 -1
- package/docs/functions/listen.html +1 -1
- package/docs/functions/listenable.html +1 -1
- package/docs/functions/loggingCallback.html +1 -1
- package/docs/index.html +40 -2
- 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-http-full.js +28 -20
- package/examples/ngrok-http-minimum.js +21 -13
- package/examples/ngrok-labeled.js +21 -17
- package/examples/ngrok-listen.js +5 -6
- package/examples/ngrok-tcp.js +21 -17
- package/examples/ngrok-tls.js +22 -19
- package/examples/ngrok-typescript.ts +31 -26
- 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 +9 -4
- package/index.js +27 -26
- package/package.json +19 -20
- package/post-build.js +18 -11
- package/scripts/gc-node-drop.js +38 -31
- package/scripts/gc-rust-drop.js +44 -38
- package/src/session.rs +3 -26
- package/src/tunnel.rs +1 -0
- package/trailer.d.ts +9 -4
- package/trailer.js +27 -26
- 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();
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
var http = require(
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
var 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
|
-
var ngrok = require(
|
|
19
|
+
var 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,23 @@ builder
|
|
|
31
34
|
console.log("restart command");
|
|
32
35
|
})
|
|
33
36
|
.handleUpdateCommand((update) => {
|
|
34
|
-
console.log(
|
|
35
|
-
|
|
37
|
+
console.log(
|
|
38
|
+
"update command, version: " +
|
|
39
|
+
update.version +
|
|
40
|
+
" permitMajorVersion: " +
|
|
41
|
+
update.permitMajorVersion
|
|
42
|
+
);
|
|
36
43
|
})
|
|
37
44
|
.handleHeartbeat((latency) => {
|
|
38
45
|
console.log("heartbeat, latency: " + latency + " milliseconds");
|
|
39
46
|
})
|
|
40
47
|
.handleDisconnection((addr, error) => {
|
|
41
|
-
console.log("disconnected, addr: " + addr
|
|
42
|
-
+ " error: " + error);
|
|
48
|
+
console.log("disconnected, addr: " + addr + " error: " + error);
|
|
43
49
|
});
|
|
44
50
|
|
|
45
51
|
builder.connect().then((session) => {
|
|
46
|
-
session
|
|
52
|
+
session
|
|
53
|
+
.httpEndpoint()
|
|
47
54
|
// .allowCidr("0.0.0.0/0")
|
|
48
55
|
// .basicAuth("ngrok", "online1line")
|
|
49
56
|
// .circuitBreaker(0.5)
|
|
@@ -62,8 +69,9 @@ builder.connect().then((session) => {
|
|
|
62
69
|
// .websocketTcpConversion()
|
|
63
70
|
// .webhookVerification("twilio", "asdf")
|
|
64
71
|
.metadata("example tunnel metadata from nodejs")
|
|
65
|
-
.listen()
|
|
66
|
-
|
|
72
|
+
.listen()
|
|
73
|
+
.then((tunnel) => {
|
|
74
|
+
console.log("established tunnel at: " + tunnel.url());
|
|
67
75
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
68
|
-
|
|
76
|
+
});
|
|
69
77
|
});
|
|
@@ -1,14 +1,22 @@
|
|
|
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
|
+
new ngrok.NgrokSessionBuilder()
|
|
12
|
+
.authtokenFromEnv()
|
|
13
|
+
.connect()
|
|
14
|
+
.then((session) => {
|
|
15
|
+
session
|
|
16
|
+
.httpEndpoint()
|
|
17
|
+
.listen()
|
|
18
|
+
.then((tunnel) => {
|
|
19
|
+
console.log("tunnel at: " + tunnel.url());
|
|
20
|
+
tunnel.forwardTcp("localhost:8081");
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
var http = require(
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
var 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
|
-
var ngrok = require(
|
|
19
|
+
var 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("established tunnel 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
|
-
var ngrok = require(
|
|
7
|
+
var ngrok = require("@ngrok/ngrok");
|
|
8
8
|
|
|
9
9
|
ngrok.listen(server).then(() => {
|
|
10
10
|
console.log("url: " + server.tunnel.url());
|
|
11
11
|
});
|
|
12
|
-
|
package/examples/ngrok-tcp.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
var http = require(
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
var 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
|
-
var ngrok = require(
|
|
19
|
+
var 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
|
var global_tunnel;
|
|
22
24
|
builder.connect().then((session) => {
|
|
23
|
-
session
|
|
25
|
+
session
|
|
26
|
+
.tcpEndpoint()
|
|
24
27
|
// .allowCidr("0.0.0.0/0")
|
|
25
28
|
// .denyCidr("10.1.1.1/32")
|
|
26
29
|
// .forwardsTo("example nodejs")
|
|
27
30
|
// .proxyProto("") // One of: "", "1", "2"
|
|
28
31
|
// .remoteAddr("<n>.tcp.ngrok.io:<p>")
|
|
29
32
|
.metadata("example tunnel metadata from nodejs")
|
|
30
|
-
.listen()
|
|
31
|
-
|
|
33
|
+
.listen()
|
|
34
|
+
.then((tunnel) => {
|
|
35
|
+
console.log("established tunnel at: " + tunnel.url());
|
|
32
36
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
33
|
-
|
|
37
|
+
});
|
|
34
38
|
});
|
package/examples/ngrok-tls.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
|
-
const fs = require(
|
|
3
|
-
try
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
try {
|
|
4
|
+
fs.unlinkSync(UNIX_SOCKET);
|
|
5
|
+
} catch {}
|
|
4
6
|
|
|
5
7
|
// make webserver
|
|
6
|
-
var http = require(
|
|
7
|
-
http
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
var 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
|
-
var ngrok = require(
|
|
19
|
+
var 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("established tunnel at: " + tunnel.url());
|
|
35
38
|
tunnel.forwardPipe(UNIX_SOCKET);
|
|
36
|
-
|
|
39
|
+
});
|
|
37
40
|
});
|