Skip to content

Commit 5603f5f

Browse files
committed
fix: should display base in remote URLs
1 parent 56d43b2 commit 5603f5f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/slidev/node/cli.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,10 @@ function printInfo(
632632
tunnelUrl?: string,
633633
publicIp?: string,
634634
) {
635-
const baseUrl = port && `http://localhost:${bold(port + (base?.slice(0, -1) || ''))}`
635+
if (base && (!base.startsWith('/') || !base.endsWith('/'))) {
636+
console.error('Base URL must start and end with a slash "/"')
637+
process.exit(1)
638+
}
636639

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

649-
if (baseUrl) {
652+
if (port) {
653+
const baseText = base?.slice(0, -1) || ''
654+
const portAndBase = port + baseText
655+
const baseUrl = `http://localhost:${bold(portAndBase)}`
650656
const query = remote ? `?password=${remote}` : ''
651657
const presenterPath = `${options.data.config.routerMode === 'hash' ? '/#/' : '/'}presenter/${query}`
652658
const entryPath = `${options.data.config.routerMode === 'hash' ? '/#/' : '/'}entry${query}/`
@@ -670,17 +676,17 @@ function printInfo(
670676
.forEach(v => (v || [])
671677
.filter(details => String(details.family).slice(-1) === '4' && !details.address.includes('127.0.0.1'))
672678
.forEach(({ address }) => {
673-
lastRemoteUrl = `http://${address}:${port}${entryPath}`
679+
lastRemoteUrl = `http://${address}:${portAndBase}${entryPath}`
674680
console.log(`${dim(' remote control ')} > ${blue(lastRemoteUrl)}`)
675681
}))
676682

677683
if (publicIp) {
678-
lastRemoteUrl = `http://${publicIp}:${port}${entryPath}`
684+
lastRemoteUrl = `http://${publicIp}:${portAndBase}${entryPath}`
679685
console.log(`${dim(' remote control ')} > ${blue(lastRemoteUrl)}`)
680686
}
681687

682688
if (tunnelUrl) {
683-
lastRemoteUrl = `${tunnelUrl}${entryPath}`
689+
lastRemoteUrl = `${tunnelUrl}${baseText}${entryPath}`
684690
console.log(`${dim(' remote via tunnel')} > ${yellow(lastRemoteUrl)}`)
685691
}
686692
}

0 commit comments

Comments
 (0)