feat: init
This commit is contained in:
200
node_modules/untun/dist/chunks/index.cjs
generated
vendored
Normal file
200
node_modules/untun/dist/chunks/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
'use strict';
|
||||
|
||||
const os = require('node:os');
|
||||
const path = require('pathe');
|
||||
const fs = require('node:fs');
|
||||
const path$1 = require('node:path');
|
||||
const https = require('node:https');
|
||||
const node_child_process = require('node:child_process');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
||||
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
||||
const path__default$1 = /*#__PURE__*/_interopDefaultCompat(path$1);
|
||||
const https__default = /*#__PURE__*/_interopDefaultCompat(https);
|
||||
|
||||
const CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "2023.10.0";
|
||||
const RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
|
||||
const cloudflaredBinPath = path__default.join(
|
||||
os.tmpdir(),
|
||||
"node-untun",
|
||||
process.platform === "win32" ? `cloudflared.${CLOUDFLARED_VERSION}.exe` : `cloudflared.${CLOUDFLARED_VERSION}`
|
||||
);
|
||||
const cloudflaredNotice = `
|
||||
\u{1F525} Your installation of cloudflared software constitutes a symbol of your signature
|
||||
indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
|
||||
|
||||
\u276F License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
|
||||
\u276F Terms: \`https://www.cloudflare.com/terms/\`
|
||||
\u276F Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
|
||||
`;
|
||||
const connRegex = /connection[ =]([\da-z-]+)/i;
|
||||
const ipRegex = /ip=([\d.]+)/;
|
||||
const locationRegex = /location=([A-Z]+)/;
|
||||
const indexRegex = /connIndex=(\d)/;
|
||||
|
||||
const LINUX_URL = {
|
||||
arm64: "cloudflared-linux-arm64",
|
||||
arm: "cloudflared-linux-arm",
|
||||
x64: "cloudflared-linux-amd64",
|
||||
ia32: "cloudflared-linux-386"
|
||||
};
|
||||
const MACOS_URL = {
|
||||
arm64: "cloudflared-darwin-amd64.tgz",
|
||||
x64: "cloudflared-darwin-amd64.tgz"
|
||||
};
|
||||
const WINDOWS_URL = {
|
||||
x64: "cloudflared-windows-amd64.exe",
|
||||
ia32: "cloudflared-windows-386.exe"
|
||||
};
|
||||
function resolveBase(version) {
|
||||
if (version === "latest") {
|
||||
return `${RELEASE_BASE}latest/download/`;
|
||||
}
|
||||
return `${RELEASE_BASE}download/${version}/`;
|
||||
}
|
||||
function installCloudflared(to = cloudflaredBinPath, version = CLOUDFLARED_VERSION) {
|
||||
switch (process.platform) {
|
||||
case "linux": {
|
||||
return installLinux(to, version);
|
||||
}
|
||||
case "darwin": {
|
||||
return installMacos(to, version);
|
||||
}
|
||||
case "win32": {
|
||||
return installWindows(to, version);
|
||||
}
|
||||
default: {
|
||||
throw new Error("Unsupported platform: " + process.platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function installLinux(to, version = CLOUDFLARED_VERSION) {
|
||||
const file = LINUX_URL[process.arch];
|
||||
if (file === void 0) {
|
||||
throw new Error("Unsupported architecture: " + process.arch);
|
||||
}
|
||||
await download(resolveBase(version) + file, to);
|
||||
fs__default.chmodSync(to, "755");
|
||||
return to;
|
||||
}
|
||||
async function installMacos(to, version = CLOUDFLARED_VERSION) {
|
||||
const file = MACOS_URL[process.arch];
|
||||
if (file === void 0) {
|
||||
throw new Error("Unsupported architecture: " + process.arch);
|
||||
}
|
||||
await download(resolveBase(version) + file, `${to}.tgz`);
|
||||
process.env.DEBUG && console.log(`Extracting to ${to}`);
|
||||
node_child_process.execSync(`tar -xzf ${path__default$1.basename(`${to}.tgz`)}`, { cwd: path__default$1.dirname(to) });
|
||||
fs__default.unlinkSync(`${to}.tgz`);
|
||||
fs__default.renameSync(`${path__default$1.dirname(to)}/cloudflared`, to);
|
||||
return to;
|
||||
}
|
||||
async function installWindows(to, version = CLOUDFLARED_VERSION) {
|
||||
const file = WINDOWS_URL[process.arch];
|
||||
if (file === void 0) {
|
||||
throw new Error("Unsupported architecture: " + process.arch);
|
||||
}
|
||||
await download(resolveBase(version) + file, to);
|
||||
return to;
|
||||
}
|
||||
function download(url, to, redirect = 0) {
|
||||
if (redirect === 0) {
|
||||
process.env.DEBUG && console.log(`Downloading ${url} to ${to}`);
|
||||
} else {
|
||||
process.env.DEBUG && console.log(`Redirecting to ${url}`);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!fs__default.existsSync(path__default$1.dirname(to))) {
|
||||
fs__default.mkdirSync(path__default$1.dirname(to), { recursive: true });
|
||||
}
|
||||
let done = true;
|
||||
const file = fs__default.createWriteStream(to);
|
||||
const request = https__default.get(url, (res) => {
|
||||
if (res.statusCode === 302 && res.headers.location !== void 0) {
|
||||
const redirection = res.headers.location;
|
||||
done = false;
|
||||
file.close(() => resolve(download(redirection, to, redirect + 1)));
|
||||
return;
|
||||
}
|
||||
res.pipe(file);
|
||||
});
|
||||
file.on("finish", () => {
|
||||
if (done) {
|
||||
file.close(() => resolve(to));
|
||||
}
|
||||
});
|
||||
request.on("error", (err) => {
|
||||
fs__default.unlink(to, () => reject(err));
|
||||
});
|
||||
file.on("error", (err) => {
|
||||
fs__default.unlink(to, () => reject(err));
|
||||
});
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
||||
function startCloudflaredTunnel(options = {}) {
|
||||
const args = ["tunnel"];
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (typeof value === "string") {
|
||||
args.push(`${key}`, value);
|
||||
} else if (typeof value === "number") {
|
||||
args.push(`${key}`, value.toString());
|
||||
} else if (value === null) {
|
||||
args.push(`${key}`);
|
||||
}
|
||||
}
|
||||
if (args.length === 1) {
|
||||
args.push("--url", "localhost:8080");
|
||||
}
|
||||
const child = node_child_process.spawn(cloudflaredBinPath, args, {
|
||||
stdio: ["ignore", "pipe", "pipe"]
|
||||
});
|
||||
if (process.env.DEBUG) {
|
||||
child.stdout.pipe(process.stdout);
|
||||
child.stderr.pipe(process.stderr);
|
||||
}
|
||||
const urlRegex = /\|\s+(https?:\/\/\S+)/;
|
||||
let urlResolver = () => void 0;
|
||||
let urlRejector = () => void 0;
|
||||
const url = new Promise(
|
||||
(...pair) => [urlResolver, urlRejector] = pair
|
||||
);
|
||||
const connectionResolvers = [];
|
||||
const connectionRejectors = [];
|
||||
const connections = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
connections.push(
|
||||
new Promise(
|
||||
(...pair) => [connectionResolvers[i], connectionRejectors[i]] = pair
|
||||
)
|
||||
);
|
||||
}
|
||||
const parser = (data) => {
|
||||
const str = data.toString();
|
||||
const urlMatch = str.match(urlRegex);
|
||||
urlMatch && urlResolver(urlMatch[1]);
|
||||
const connMatch = str.match(connRegex);
|
||||
const ipMatch = str.match(ipRegex);
|
||||
const locationMatch = str.match(locationRegex);
|
||||
const indexMatch = str.match(indexRegex);
|
||||
if (connMatch && ipMatch && locationMatch && indexMatch) {
|
||||
const [, id] = connMatch;
|
||||
const [, ip] = ipMatch;
|
||||
const [, location] = locationMatch;
|
||||
const [, idx] = indexMatch;
|
||||
connectionResolvers[+idx]?.({ id, ip, location });
|
||||
}
|
||||
};
|
||||
child.stdout.on("data", parser).on("error", urlRejector);
|
||||
child.stderr.on("data", parser).on("error", urlRejector);
|
||||
const stop = () => child.kill("SIGINT");
|
||||
return { url, connections, child, stop };
|
||||
}
|
||||
|
||||
exports.cloudflaredBinPath = cloudflaredBinPath;
|
||||
exports.cloudflaredNotice = cloudflaredNotice;
|
||||
exports.installCloudflared = installCloudflared;
|
||||
exports.startCloudflaredTunnel = startCloudflaredTunnel;
|
||||
188
node_modules/untun/dist/chunks/index.mjs
generated
vendored
Normal file
188
node_modules/untun/dist/chunks/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'pathe';
|
||||
import fs from 'node:fs';
|
||||
import path$1 from 'node:path';
|
||||
import https from 'node:https';
|
||||
import { execSync, spawn } from 'node:child_process';
|
||||
|
||||
const CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "2023.10.0";
|
||||
const RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
|
||||
const cloudflaredBinPath = path.join(
|
||||
tmpdir(),
|
||||
"node-untun",
|
||||
process.platform === "win32" ? `cloudflared.${CLOUDFLARED_VERSION}.exe` : `cloudflared.${CLOUDFLARED_VERSION}`
|
||||
);
|
||||
const cloudflaredNotice = `
|
||||
\u{1F525} Your installation of cloudflared software constitutes a symbol of your signature
|
||||
indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
|
||||
|
||||
\u276F License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
|
||||
\u276F Terms: \`https://www.cloudflare.com/terms/\`
|
||||
\u276F Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
|
||||
`;
|
||||
const connRegex = /connection[ =]([\da-z-]+)/i;
|
||||
const ipRegex = /ip=([\d.]+)/;
|
||||
const locationRegex = /location=([A-Z]+)/;
|
||||
const indexRegex = /connIndex=(\d)/;
|
||||
|
||||
const LINUX_URL = {
|
||||
arm64: "cloudflared-linux-arm64",
|
||||
arm: "cloudflared-linux-arm",
|
||||
x64: "cloudflared-linux-amd64",
|
||||
ia32: "cloudflared-linux-386"
|
||||
};
|
||||
const MACOS_URL = {
|
||||
arm64: "cloudflared-darwin-amd64.tgz",
|
||||
x64: "cloudflared-darwin-amd64.tgz"
|
||||
};
|
||||
const WINDOWS_URL = {
|
||||
x64: "cloudflared-windows-amd64.exe",
|
||||
ia32: "cloudflared-windows-386.exe"
|
||||
};
|
||||
function resolveBase(version) {
|
||||
if (version === "latest") {
|
||||
return `${RELEASE_BASE}latest/download/`;
|
||||
}
|
||||
return `${RELEASE_BASE}download/${version}/`;
|
||||
}
|
||||
function installCloudflared(to = cloudflaredBinPath, version = CLOUDFLARED_VERSION) {
|
||||
switch (process.platform) {
|
||||
case "linux": {
|
||||
return installLinux(to, version);
|
||||
}
|
||||
case "darwin": {
|
||||
return installMacos(to, version);
|
||||
}
|
||||
case "win32": {
|
||||
return installWindows(to, version);
|
||||
}
|
||||
default: {
|
||||
throw new Error("Unsupported platform: " + process.platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function installLinux(to, version = CLOUDFLARED_VERSION) {
|
||||
const file = LINUX_URL[process.arch];
|
||||
if (file === void 0) {
|
||||
throw new Error("Unsupported architecture: " + process.arch);
|
||||
}
|
||||
await download(resolveBase(version) + file, to);
|
||||
fs.chmodSync(to, "755");
|
||||
return to;
|
||||
}
|
||||
async function installMacos(to, version = CLOUDFLARED_VERSION) {
|
||||
const file = MACOS_URL[process.arch];
|
||||
if (file === void 0) {
|
||||
throw new Error("Unsupported architecture: " + process.arch);
|
||||
}
|
||||
await download(resolveBase(version) + file, `${to}.tgz`);
|
||||
process.env.DEBUG && console.log(`Extracting to ${to}`);
|
||||
execSync(`tar -xzf ${path$1.basename(`${to}.tgz`)}`, { cwd: path$1.dirname(to) });
|
||||
fs.unlinkSync(`${to}.tgz`);
|
||||
fs.renameSync(`${path$1.dirname(to)}/cloudflared`, to);
|
||||
return to;
|
||||
}
|
||||
async function installWindows(to, version = CLOUDFLARED_VERSION) {
|
||||
const file = WINDOWS_URL[process.arch];
|
||||
if (file === void 0) {
|
||||
throw new Error("Unsupported architecture: " + process.arch);
|
||||
}
|
||||
await download(resolveBase(version) + file, to);
|
||||
return to;
|
||||
}
|
||||
function download(url, to, redirect = 0) {
|
||||
if (redirect === 0) {
|
||||
process.env.DEBUG && console.log(`Downloading ${url} to ${to}`);
|
||||
} else {
|
||||
process.env.DEBUG && console.log(`Redirecting to ${url}`);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!fs.existsSync(path$1.dirname(to))) {
|
||||
fs.mkdirSync(path$1.dirname(to), { recursive: true });
|
||||
}
|
||||
let done = true;
|
||||
const file = fs.createWriteStream(to);
|
||||
const request = https.get(url, (res) => {
|
||||
if (res.statusCode === 302 && res.headers.location !== void 0) {
|
||||
const redirection = res.headers.location;
|
||||
done = false;
|
||||
file.close(() => resolve(download(redirection, to, redirect + 1)));
|
||||
return;
|
||||
}
|
||||
res.pipe(file);
|
||||
});
|
||||
file.on("finish", () => {
|
||||
if (done) {
|
||||
file.close(() => resolve(to));
|
||||
}
|
||||
});
|
||||
request.on("error", (err) => {
|
||||
fs.unlink(to, () => reject(err));
|
||||
});
|
||||
file.on("error", (err) => {
|
||||
fs.unlink(to, () => reject(err));
|
||||
});
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
||||
function startCloudflaredTunnel(options = {}) {
|
||||
const args = ["tunnel"];
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (typeof value === "string") {
|
||||
args.push(`${key}`, value);
|
||||
} else if (typeof value === "number") {
|
||||
args.push(`${key}`, value.toString());
|
||||
} else if (value === null) {
|
||||
args.push(`${key}`);
|
||||
}
|
||||
}
|
||||
if (args.length === 1) {
|
||||
args.push("--url", "localhost:8080");
|
||||
}
|
||||
const child = spawn(cloudflaredBinPath, args, {
|
||||
stdio: ["ignore", "pipe", "pipe"]
|
||||
});
|
||||
if (process.env.DEBUG) {
|
||||
child.stdout.pipe(process.stdout);
|
||||
child.stderr.pipe(process.stderr);
|
||||
}
|
||||
const urlRegex = /\|\s+(https?:\/\/\S+)/;
|
||||
let urlResolver = () => void 0;
|
||||
let urlRejector = () => void 0;
|
||||
const url = new Promise(
|
||||
(...pair) => [urlResolver, urlRejector] = pair
|
||||
);
|
||||
const connectionResolvers = [];
|
||||
const connectionRejectors = [];
|
||||
const connections = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
connections.push(
|
||||
new Promise(
|
||||
(...pair) => [connectionResolvers[i], connectionRejectors[i]] = pair
|
||||
)
|
||||
);
|
||||
}
|
||||
const parser = (data) => {
|
||||
const str = data.toString();
|
||||
const urlMatch = str.match(urlRegex);
|
||||
urlMatch && urlResolver(urlMatch[1]);
|
||||
const connMatch = str.match(connRegex);
|
||||
const ipMatch = str.match(ipRegex);
|
||||
const locationMatch = str.match(locationRegex);
|
||||
const indexMatch = str.match(indexRegex);
|
||||
if (connMatch && ipMatch && locationMatch && indexMatch) {
|
||||
const [, id] = connMatch;
|
||||
const [, ip] = ipMatch;
|
||||
const [, location] = locationMatch;
|
||||
const [, idx] = indexMatch;
|
||||
connectionResolvers[+idx]?.({ id, ip, location });
|
||||
}
|
||||
};
|
||||
child.stdout.on("data", parser).on("error", urlRejector);
|
||||
child.stderr.on("data", parser).on("error", urlRejector);
|
||||
const stop = () => child.kill("SIGINT");
|
||||
return { url, connections, child, stop };
|
||||
}
|
||||
|
||||
export { cloudflaredBinPath, cloudflaredNotice, installCloudflared, startCloudflaredTunnel };
|
||||
68
node_modules/untun/dist/cli.cjs
generated
vendored
Normal file
68
node_modules/untun/dist/cli.cjs
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
|
||||
const citty = require('citty');
|
||||
const consola = require('consola');
|
||||
const index = require('./index.cjs');
|
||||
require('node:fs');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
||||
|
||||
const name = "untun";
|
||||
const version = "0.1.3";
|
||||
const description = "Tunnel your local HTTP(s) server to the world! Powered by Cloudflare Quick Tunnels.";
|
||||
|
||||
const tunnel = citty.defineCommand({
|
||||
meta: {
|
||||
name: "tunnel",
|
||||
description: "Create a tunnel to a local server"
|
||||
},
|
||||
args: {
|
||||
url: {
|
||||
type: "positional",
|
||||
description: "The URL of the tunnel",
|
||||
required: false
|
||||
},
|
||||
port: {
|
||||
type: "string",
|
||||
description: "The port of the tunnel (default: 3000)"
|
||||
},
|
||||
hostname: {
|
||||
type: "string",
|
||||
description: "The hostname of the tunnel (default: localhost)",
|
||||
valueHint: "localhost|example.com"
|
||||
},
|
||||
protocol: {
|
||||
type: "string",
|
||||
description: "The protocol of the tunnel (default: http)",
|
||||
valueHint: "http|https"
|
||||
}
|
||||
},
|
||||
async run({ args }) {
|
||||
const tunnel2 = await index.startTunnel({
|
||||
url: args.url
|
||||
});
|
||||
if (!tunnel2) {
|
||||
console.log("Tunnel not started.");
|
||||
process.exit(1);
|
||||
}
|
||||
consola__default.info("Waiting for tunnel URL...");
|
||||
consola__default.success(`Tunnel ready at \`${await tunnel2.getURL()}\``);
|
||||
}
|
||||
});
|
||||
const main = citty.defineCommand({
|
||||
meta: {
|
||||
name,
|
||||
description,
|
||||
version
|
||||
},
|
||||
subCommands: {
|
||||
tunnel
|
||||
}
|
||||
});
|
||||
const runMain = () => citty.runMain(main);
|
||||
|
||||
exports.main = main;
|
||||
exports.runMain = runMain;
|
||||
exports.tunnel = tunnel;
|
||||
27
node_modules/untun/dist/cli.d.cts
generated
vendored
Normal file
27
node_modules/untun/dist/cli.d.cts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as citty from 'citty';
|
||||
|
||||
declare const tunnel: citty.CommandDef<{
|
||||
url: {
|
||||
type: "positional";
|
||||
description: string;
|
||||
required: false;
|
||||
};
|
||||
port: {
|
||||
type: "string";
|
||||
description: string;
|
||||
};
|
||||
hostname: {
|
||||
type: "string";
|
||||
description: string;
|
||||
valueHint: string;
|
||||
};
|
||||
protocol: {
|
||||
type: "string";
|
||||
description: string;
|
||||
valueHint: string;
|
||||
};
|
||||
}>;
|
||||
declare const main: citty.CommandDef<citty.ArgsDef>;
|
||||
declare const runMain: () => Promise<void>;
|
||||
|
||||
export { main, runMain, tunnel };
|
||||
27
node_modules/untun/dist/cli.d.mts
generated
vendored
Normal file
27
node_modules/untun/dist/cli.d.mts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as citty from 'citty';
|
||||
|
||||
declare const tunnel: citty.CommandDef<{
|
||||
url: {
|
||||
type: "positional";
|
||||
description: string;
|
||||
required: false;
|
||||
};
|
||||
port: {
|
||||
type: "string";
|
||||
description: string;
|
||||
};
|
||||
hostname: {
|
||||
type: "string";
|
||||
description: string;
|
||||
valueHint: string;
|
||||
};
|
||||
protocol: {
|
||||
type: "string";
|
||||
description: string;
|
||||
valueHint: string;
|
||||
};
|
||||
}>;
|
||||
declare const main: citty.CommandDef<citty.ArgsDef>;
|
||||
declare const runMain: () => Promise<void>;
|
||||
|
||||
export { main, runMain, tunnel };
|
||||
27
node_modules/untun/dist/cli.d.ts
generated
vendored
Normal file
27
node_modules/untun/dist/cli.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as citty from 'citty';
|
||||
|
||||
declare const tunnel: citty.CommandDef<{
|
||||
url: {
|
||||
type: "positional";
|
||||
description: string;
|
||||
required: false;
|
||||
};
|
||||
port: {
|
||||
type: "string";
|
||||
description: string;
|
||||
};
|
||||
hostname: {
|
||||
type: "string";
|
||||
description: string;
|
||||
valueHint: string;
|
||||
};
|
||||
protocol: {
|
||||
type: "string";
|
||||
description: string;
|
||||
valueHint: string;
|
||||
};
|
||||
}>;
|
||||
declare const main: citty.CommandDef<citty.ArgsDef>;
|
||||
declare const runMain: () => Promise<void>;
|
||||
|
||||
export { main, runMain, tunnel };
|
||||
60
node_modules/untun/dist/cli.mjs
generated
vendored
Normal file
60
node_modules/untun/dist/cli.mjs
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { defineCommand, runMain as runMain$1 } from 'citty';
|
||||
import consola from 'consola';
|
||||
import { startTunnel } from './index.mjs';
|
||||
import 'node:fs';
|
||||
|
||||
const name = "untun";
|
||||
const version = "0.1.3";
|
||||
const description = "Tunnel your local HTTP(s) server to the world! Powered by Cloudflare Quick Tunnels.";
|
||||
|
||||
const tunnel = defineCommand({
|
||||
meta: {
|
||||
name: "tunnel",
|
||||
description: "Create a tunnel to a local server"
|
||||
},
|
||||
args: {
|
||||
url: {
|
||||
type: "positional",
|
||||
description: "The URL of the tunnel",
|
||||
required: false
|
||||
},
|
||||
port: {
|
||||
type: "string",
|
||||
description: "The port of the tunnel (default: 3000)"
|
||||
},
|
||||
hostname: {
|
||||
type: "string",
|
||||
description: "The hostname of the tunnel (default: localhost)",
|
||||
valueHint: "localhost|example.com"
|
||||
},
|
||||
protocol: {
|
||||
type: "string",
|
||||
description: "The protocol of the tunnel (default: http)",
|
||||
valueHint: "http|https"
|
||||
}
|
||||
},
|
||||
async run({ args }) {
|
||||
const tunnel2 = await startTunnel({
|
||||
url: args.url
|
||||
});
|
||||
if (!tunnel2) {
|
||||
console.log("Tunnel not started.");
|
||||
process.exit(1);
|
||||
}
|
||||
consola.info("Waiting for tunnel URL...");
|
||||
consola.success(`Tunnel ready at \`${await tunnel2.getURL()}\``);
|
||||
}
|
||||
});
|
||||
const main = defineCommand({
|
||||
meta: {
|
||||
name,
|
||||
description,
|
||||
version
|
||||
},
|
||||
subCommands: {
|
||||
tunnel
|
||||
}
|
||||
});
|
||||
const runMain = () => runMain$1(main);
|
||||
|
||||
export { main, runMain, tunnel };
|
||||
52
node_modules/untun/dist/index.cjs
generated
vendored
Normal file
52
node_modules/untun/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
const consola = require('consola');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
||||
|
||||
async function startTunnel(opts) {
|
||||
const {
|
||||
installCloudflared,
|
||||
startCloudflaredTunnel,
|
||||
cloudflaredBinPath,
|
||||
cloudflaredNotice
|
||||
} = await import('./chunks/index.cjs');
|
||||
const url = opts.url || `${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3e3}`;
|
||||
consola__default.start(`Starting cloudflared tunnel to ${url}`);
|
||||
if (!fs.existsSync(cloudflaredBinPath)) {
|
||||
consola__default.log(cloudflaredNotice);
|
||||
const canInstall = opts.acceptCloudflareNotice || process.env.UNTUN_ACCEPT_CLOUDFLARE_NOTICE || await consola__default.prompt(
|
||||
`Do you agree with the above terms and wish to install the binary from GitHub?`,
|
||||
{
|
||||
type: "confirm"
|
||||
}
|
||||
);
|
||||
if (!canInstall) {
|
||||
consola__default.fail("Skipping tunnel setup.");
|
||||
return;
|
||||
}
|
||||
await installCloudflared();
|
||||
}
|
||||
const args = [
|
||||
["--url", url],
|
||||
opts.verifyTLS ? void 0 : ["--no-tls-verify", ""]
|
||||
].filter(Boolean);
|
||||
const tunnel = await startCloudflaredTunnel(Object.fromEntries(args));
|
||||
const cleanup = async () => {
|
||||
await tunnel.stop();
|
||||
};
|
||||
for (const signal of ["SIGINT", "SIGUSR1", "SIGUSR2"]) {
|
||||
process.once(signal, cleanup);
|
||||
}
|
||||
return {
|
||||
getURL: async () => await tunnel.url,
|
||||
close: async () => {
|
||||
await cleanup();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.startTunnel = startTunnel;
|
||||
15
node_modules/untun/dist/index.d.cts
generated
vendored
Normal file
15
node_modules/untun/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
interface TunnelOptions {
|
||||
url?: string;
|
||||
port?: number | string;
|
||||
hostname?: string;
|
||||
protocol?: "http" | "https";
|
||||
verifyTLS?: boolean;
|
||||
acceptCloudflareNotice?: boolean;
|
||||
}
|
||||
interface Tunnel {
|
||||
getURL: () => Promise<string>;
|
||||
close: () => Promise<void>;
|
||||
}
|
||||
declare function startTunnel(opts: TunnelOptions): Promise<undefined | Tunnel>;
|
||||
|
||||
export { type Tunnel, type TunnelOptions, startTunnel };
|
||||
15
node_modules/untun/dist/index.d.mts
generated
vendored
Normal file
15
node_modules/untun/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
interface TunnelOptions {
|
||||
url?: string;
|
||||
port?: number | string;
|
||||
hostname?: string;
|
||||
protocol?: "http" | "https";
|
||||
verifyTLS?: boolean;
|
||||
acceptCloudflareNotice?: boolean;
|
||||
}
|
||||
interface Tunnel {
|
||||
getURL: () => Promise<string>;
|
||||
close: () => Promise<void>;
|
||||
}
|
||||
declare function startTunnel(opts: TunnelOptions): Promise<undefined | Tunnel>;
|
||||
|
||||
export { type Tunnel, type TunnelOptions, startTunnel };
|
||||
15
node_modules/untun/dist/index.d.ts
generated
vendored
Normal file
15
node_modules/untun/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
interface TunnelOptions {
|
||||
url?: string;
|
||||
port?: number | string;
|
||||
hostname?: string;
|
||||
protocol?: "http" | "https";
|
||||
verifyTLS?: boolean;
|
||||
acceptCloudflareNotice?: boolean;
|
||||
}
|
||||
interface Tunnel {
|
||||
getURL: () => Promise<string>;
|
||||
close: () => Promise<void>;
|
||||
}
|
||||
declare function startTunnel(opts: TunnelOptions): Promise<undefined | Tunnel>;
|
||||
|
||||
export { type Tunnel, type TunnelOptions, startTunnel };
|
||||
46
node_modules/untun/dist/index.mjs
generated
vendored
Normal file
46
node_modules/untun/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import { existsSync } from 'node:fs';
|
||||
import consola from 'consola';
|
||||
|
||||
async function startTunnel(opts) {
|
||||
const {
|
||||
installCloudflared,
|
||||
startCloudflaredTunnel,
|
||||
cloudflaredBinPath,
|
||||
cloudflaredNotice
|
||||
} = await import('./chunks/index.mjs');
|
||||
const url = opts.url || `${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3e3}`;
|
||||
consola.start(`Starting cloudflared tunnel to ${url}`);
|
||||
if (!existsSync(cloudflaredBinPath)) {
|
||||
consola.log(cloudflaredNotice);
|
||||
const canInstall = opts.acceptCloudflareNotice || process.env.UNTUN_ACCEPT_CLOUDFLARE_NOTICE || await consola.prompt(
|
||||
`Do you agree with the above terms and wish to install the binary from GitHub?`,
|
||||
{
|
||||
type: "confirm"
|
||||
}
|
||||
);
|
||||
if (!canInstall) {
|
||||
consola.fail("Skipping tunnel setup.");
|
||||
return;
|
||||
}
|
||||
await installCloudflared();
|
||||
}
|
||||
const args = [
|
||||
["--url", url],
|
||||
opts.verifyTLS ? void 0 : ["--no-tls-verify", ""]
|
||||
].filter(Boolean);
|
||||
const tunnel = await startCloudflaredTunnel(Object.fromEntries(args));
|
||||
const cleanup = async () => {
|
||||
await tunnel.stop();
|
||||
};
|
||||
for (const signal of ["SIGINT", "SIGUSR1", "SIGUSR2"]) {
|
||||
process.once(signal, cleanup);
|
||||
}
|
||||
return {
|
||||
getURL: async () => await tunnel.url,
|
||||
close: async () => {
|
||||
await cleanup();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { startTunnel };
|
||||
Reference in New Issue
Block a user