-
Notifications
You must be signed in to change notification settings - Fork 15
/
ngrok-tls.js
40 lines (37 loc) · 1.23 KB
/
ngrok-tls.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
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");
builder = new ngrok.SessionBuilder();
builder.authtokenFromEnv().metadata("Online in One Line");
builder.connect().then((session) => {
console.log("established session");
session
.tlsEndpoint()
// .allowCidr("0.0.0.0/0")
// .denyCidr("10.1.1.1/32")
// .domain("<somedomain>.ngrok.io")
// .forwardsTo("example nodejs")
// .mutualTlsca(fs.readFileSync('ca.crt'))
// .proxyProto("") // One of: "", "1", "2"
.termination(fs.readFileSync("domain.crt"), fs.readFileSync("domain.key"))
.metadata("example listener metadata from nodejs")
.listen()
.then((listener) => {
console.log("Ingress established at:", listener.url());
listener.forward(UNIX_SOCKET);
});
});