Skip to content

Commit

Permalink
feat: use untun instead of localtunnel (#1225) (#1286)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
KermanX and antfu committed Feb 13, 2024
1 parent 4f6f57b commit d6bb539
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 143 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@types/fs-extra": "^11.0.4",
"@types/js-yaml": "^4.0.9",
"@types/katex": "^0.16.7",
"@types/localtunnel": "^2.0.4",
"@types/markdown-it": "^13.0.7",
"@types/node": "^20.11.17",
"@types/prismjs": "^1.26.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/slidev/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cli.command(
.option('tunnel', {
default: false,
type: 'boolean',
describe: 'open localtunnel to make Slidev available on the internet',
describe: 'open a Cloudflare Quick Tunnel to make Slidev available on the internet',
})
.option('log', {
default: 'warn',
Expand Down Expand Up @@ -163,7 +163,7 @@ cli.command(
if (remote != null)
tunnelUrl = await openTunnel(port)
else
console.log(yellow('\n --remote is required for tunneling, localtunnel is not enabled.\n'))
console.log(yellow('\n --remote is required for tunneling, Cloudflare Quick Tunnel is not enabled.\n'))
}

let publicIp: string | undefined
Expand All @@ -174,12 +174,12 @@ cli.command(
}

async function openTunnel(port: number) {
const localtunnel = await import('localtunnel').then(r => r.default || r)
const tunnel = await localtunnel({
const { startTunnel } = await import('untun')
const tunnel = await startTunnel({
port,
local_host: '0.0.0.0',
acceptCloudflareNotice: true,
})
return tunnel.url
return await tunnel?.getURL() ?? ''
}

const SHORTCUTS = [
Expand Down
2 changes: 1 addition & 1 deletion packages/slidev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"katex": "^0.16.9",
"kolorist": "^1.8.0",
"local-pkg": "^0.5.0",
"localtunnel": "^2.0.2",
"markdown-it": "^14.0.0",
"markdown-it-footnote": "^4.0.0",
"markdown-it-link-attributes": "^4.0.1",
Expand All @@ -104,6 +103,7 @@
"unplugin-icons": "^0.18.5",
"unplugin-vue-components": "^0.26.0",
"unplugin-vue-markdown": "^0.26.0",
"untun": "^0.1.3",
"uqr": "^0.1.2",
"vite": "^5.1.1",
"vite-plugin-inspect": "^0.8.3",
Expand Down
Loading

0 comments on commit d6bb539

Please sign in to comment.