import axios from "axios"; import https from "https"; import localtunnel from "localtunnel"; var HttpsMethod; (function (HttpsMethod) { HttpsMethod["None"] = "none"; HttpsMethod["LocalIpMedic"] = "local-ip.medicmobile.org"; HttpsMethod["LocalIpCo"] = "local-ip.co"; HttpsMethod["Localtunnel"] = "localtunnel"; })(HttpsMethod || (HttpsMethod = {})); const HTTPS_METHOD = process.env.HTTPS_METHOD || HttpsMethod.None; export const serveHTTPS = async (app, port) => { if (HTTPS_METHOD === HttpsMethod.LocalIpMedic) { const json = (await axios.get("https://local-ip.medicmobile.org/keys")) .data; const cert = `${json.cert}\n${json.chain}`; const httpsServer = https.createServer({ key: json.privkey, cert }, app); httpsServer.listen(port); console.log(`HTTPS addon listening on port ${port}`); return httpsServer; } if (HTTPS_METHOD === HttpsMethod.LocalIpCo) { const key = (await axios.get("http://local-ip.co/cert/server.key")).data; const serverPem = (await axios.get("http://local-ip.co/cert/server.pem")) .data; const chainPem = (await axios.get("http://local-ip.co/cert/chain.pem")) .data; const cert = `${serverPem}\n${chainPem}`; const httpsServer = https.createServer({ key, cert }, app); httpsServer.listen(port); console.log(`HTTPS addon listening on port ${port}`); return httpsServer; } if (HTTPS_METHOD === HttpsMethod.Localtunnel) { const tunnel = await localtunnel({ port: Number(process.env.PORT) }); console.log(`Tunnel accessible at: ${tunnel.url}`); const tunnelPassword = await axios.get("https://loca.lt/mytunnelpassword"); console.log(`Tunnel password: ${tunnelPassword.data}`); } }; //# sourceMappingURL=https.js.map