-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtunnel.mjs
46 lines (38 loc) · 1.36 KB
/
tunnel.mjs
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
import localtunnel from "localtunnel";
import open from "open";
import "dotenv/config";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
let tunnel;
if (!process.env.LOCALTUNNEL_SUBDOMAIN) {
tunnel = await localtunnel({ port: 3001 });
const envPath = path.resolve(__dirname, ".env");
const tunnelSubdomain = splitLocalTunnelUrl(tunnel.url);
fs.appendFileSync(envPath, `LOCALTUNNEL_SUBDOMAIN=${tunnelSubdomain}\n`);
console.log(`created new tunnel: ${tunnelSubdomain}`);
} else {
tunnel = await localtunnel({
port: 3001,
subdomain: process.env.LOCALTUNNEL_SUBDOMAIN,
});
const tunnelSubdomain = splitLocalTunnelUrl(tunnel.url);
if (tunnelSubdomain !== process.env.LOCALTUNNEL_SUBDOMAIN) {
console.log(`🚨🚨🚨 localtunnel subdomain mismatch 🚨🚨🚨`);
console.log(
`you will likely have to re-add this URL to Neon in the Neon Authorize settings`
);
} else {
console.log(`reusing existing tunnel ${tunnelSubdomain}`);
}
}
const jwksURL = `${tunnel.url}/auth/jwt/jwks.json`;
console.log(`this is your jwks URL: ${jwksURL}`);
open(jwksURL);
})();
function splitLocalTunnelUrl(url) {
return url.split("//")[1].split(".")[0];
}