UNPKG

@mikkel-ol/tunnelmole

Version:

Tunnelmole, an open source ngrok alternative. Instant public URLs for any http/https based application. Available as a command line application or as an NPM dependency for your code. Stable and maintained. Good test coverage. Works behind firewalls

38 lines 2.04 kB
import { eventHandler, URL_ASSIGNED } from "../events/event-handler.js"; import chalk from "chalk"; import { getConnectionInfo } from "../websocket/connection-info-service.js"; export default async function hostnameAssigned(message, websocket, options) { const port = options.port; if (typeof port === "undefined") { console.error('Please specify a port e.g. run "tmole 80"'); } const httpsUrl = `https://${message.hostname}`; const httpUrl = `http://${message.hostname}`; const destinationUrl = `http://localhost:${port}`; const encodedHttpsUrl = Buffer.from(httpsUrl).toString("base64"); const isCli = getConnectionInfo().isCli; if (isCli) { eventHandler.emit(URL_ASSIGNED, httpsUrl); return; } if (process.env.TUNNELMOLE_QUIET_MODE !== "1") { console.info("=".repeat(process.stdout.columns)); console.info("Your Tunnelmole Public URLs are below and are accessible internet wide. Always use HTTPs for the best security"); console.info(""); console.info(`${chalk.greenBright.bold(httpsUrl)}${chalk.bold(destinationUrl)}`); console.info(`${chalk.greenBright.bold(httpUrl)}${chalk.bold(destinationUrl)}`); console.info("=".repeat(process.stdout.columns)); } console.info(chalk.bold("\nShare your creation with the world!")); printSharingNetwork("Reddit", "reddit", encodedHttpsUrl); printSharingNetwork("Hacker News", "hackernews", encodedHttpsUrl); printSharingNetwork("BlueSky", "bluesky", encodedHttpsUrl); printSharingNetwork("X (Twitter)", "twitter", encodedHttpsUrl); printSharingNetwork("LinkedIn", "linkedin", encodedHttpsUrl); eventHandler.emit(URL_ASSIGNED, httpsUrl); } const printSharingNetwork = (displayNetworkName, network, encodedHttpsUrl) => { const shareUrl = `https://dashboard.tunnelmole.com/share/${network}/${encodedHttpsUrl}`; console.info(`${displayNetworkName}: ${chalk.greenBright.bold(shareUrl)}`); }; //# sourceMappingURL=hostname-assigned.js.map