Skip to content

Commit

Permalink
fix: should display base in remote URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
kermanx committed Feb 3, 2025
1 parent 56d43b2 commit 5603f5f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/slidev/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ function printInfo(
tunnelUrl?: string,
publicIp?: string,
) {
const baseUrl = port && `http://localhost:${bold(port + (base?.slice(0, -1) || ''))}`
if (base && (!base.startsWith('/') || !base.endsWith('/'))) {
console.error('Base URL must start and end with a slash "/"')
process.exit(1)
}

console.log()
console.log()
Expand All @@ -646,7 +649,10 @@ function printInfo(
console.log(dim(' css engine ') + blue('unocss'))
console.log(dim(' entry ') + dim(path.normalize(path.dirname(options.entry)) + path.sep) + path.basename(options.entry))

if (baseUrl) {
if (port) {
const baseText = base?.slice(0, -1) || ''
const portAndBase = port + baseText
const baseUrl = `http://localhost:${bold(portAndBase)}`
const query = remote ? `?password=${remote}` : ''
const presenterPath = `${options.data.config.routerMode === 'hash' ? '/#/' : '/'}presenter/${query}`
const entryPath = `${options.data.config.routerMode === 'hash' ? '/#/' : '/'}entry${query}/`
Expand All @@ -670,17 +676,17 @@ function printInfo(
.forEach(v => (v || [])
.filter(details => String(details.family).slice(-1) === '4' && !details.address.includes('127.0.0.1'))
.forEach(({ address }) => {
lastRemoteUrl = `http://${address}:${port}${entryPath}`
lastRemoteUrl = `http://${address}:${portAndBase}${entryPath}`
console.log(`${dim(' remote control ')} > ${blue(lastRemoteUrl)}`)
}))

if (publicIp) {
lastRemoteUrl = `http://${publicIp}:${port}${entryPath}`
lastRemoteUrl = `http://${publicIp}:${portAndBase}${entryPath}`
console.log(`${dim(' remote control ')} > ${blue(lastRemoteUrl)}`)
}

if (tunnelUrl) {
lastRemoteUrl = `${tunnelUrl}${entryPath}`
lastRemoteUrl = `${tunnelUrl}${baseText}${entryPath}`
console.log(`${dim(' remote via tunnel')} > ${yellow(lastRemoteUrl)}`)
}
}
Expand Down

0 comments on commit 5603f5f

Please sign in to comment.