-
Notifications
You must be signed in to change notification settings - Fork 15
/
ngrok-http-full.js
82 lines (78 loc) · 2.55 KB
/
ngrok-http-full.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const UNIX_SOCKET = "/tmp/http.socket";
const fs = require("fs");
try {
fs.unlinkSync(UNIX_SOCKET);
} catch {}
// make webserver
const http = require("http");
http
.createServer(function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
res.write("Congrats you have a created an ngrok web server");
res.end();
})
.listen(UNIX_SOCKET); // Server object listens on unix socket
console.log("Node.js web server at", UNIX_SOCKET, "is running..");
// setup ngrok
const ngrok = require("@ngrok/ngrok");
// import ngrok from '@ngrok/ngrok' // if inside a module
ngrok.consoleLog("INFO"); // turn on info logging
builder = new ngrok.SessionBuilder();
builder
// .authtoken("<authtoken>")
.authtokenFromEnv()
.metadata("Online in One Line")
.clientInfo("ngrok-http-full", "1.2.3")
// .caCert(fs.readFileSync('ca.crt'))
// .serverAddr('192.168.1.1:443')
.handleStopCommand(() => {
console.log("stop command");
})
.handleRestartCommand(() => {
console.log("restart command");
})
.handleUpdateCommand((update) => {
console.log(
"update command, version:",
update.version,
"permitMajorVersion:",
update.permitMajorVersion
);
})
.handleHeartbeat((latency) => {
console.log("heartbeat, latency:", latency, "milliseconds");
})
.handleDisconnection((addr, error) => {
console.log("disconnected, addr:", addr, "error:", error);
});
builder.connect().then((session) => {
session
.httpEndpoint()
// .allowCidr("0.0.0.0/0")
// .allowUserAgent("^mozilla.*")
// .basicAuth("ngrok", "online1line")
// .circuitBreaker(0.5)
// .compression()
// .denyCidr("10.1.1.1/32")
// .denyUserAgent("^curl.*")
// .domain("<somedomain>.ngrok.io")
// .mutualTlsca(fs.readFileSync('ca.crt'))
// .oauth("google", ["<user>@<domain>"], ["<domain>"])
// .oauth("google", ["<user>@<domain>"], ["<domain>"], ["<scope>"], "<id>", "<secret>")
// .oidc("<url>", "<id>", "<secret>", ["<user>@<domain>"], ["<domain>"], ["<scope>"])
// .proxyProto("") // One of: "", "1", "2"
// .removeRequestHeader("X-Req-Nope")
// .removeResponseHeader("X-Res-Nope")
// .requestHeader("X-Req-Yup", "true")
// .responseHeader("X-Res-Yup", "true")
// .scheme("HTTPS")
// .verifyUpstreamTls(false)
// .websocketTcpConversion()
// .webhookVerification("twilio", "asdf")
.metadata("example listener metadata from nodejs")
.listen()
.then((listener) => {
console.log("Ingress established at:", listener.url());
listener.forward(UNIX_SOCKET);
});
});