(options: { subdomain: string; url: string })
| 2 | import localtunnel from "localtunnel"; |
| 3 | |
| 4 | const createTunnel = (options: { subdomain: string; url: string }): Promise<never> => { |
| 5 | return new Promise<never>((resolve, reject) => { |
| 6 | localtunnel({ |
| 7 | port: 3000, |
| 8 | subdomain: options.subdomain, |
| 9 | }) |
| 10 | .then((tunnel) => { |
| 11 | console.log(`Tunnel Opened: ${tunnel.url}`); |
| 12 | if (tunnel.url !== options.url) { |
| 13 | tunnel.close(); |
| 14 | return reject(`URL Mismatch: Expected ${options.url}, got ${tunnel.url}`); |
| 15 | } |
| 16 | |
| 17 | tunnel.on("error", (err: Error) => { |
| 18 | reject(`Tunnel Error: ${err.message}`); |
| 19 | }); |
| 20 | |
| 21 | tunnel.on("close", () => { |
| 22 | reject("Tunnel Closed"); |
| 23 | }); |
| 24 | }) |
| 25 | .catch((err: Error) => { |
| 26 | reject(`Failed to open tunnel: ${err.message}`); |
| 27 | }); |
| 28 | }); |
| 29 | }; |
| 30 | |
| 31 | if (!process.env.LOCAL_HOST_PUBLIC_URL) { |
| 32 | throw new Error("LOCAL_HOST_PUBLIC_URL must be set"); |
no test coverage detected