Skip to content

Commit c78d105

Browse files
committed
chore: refactor to logToConsole
chore: wip
1 parent 94089f5 commit c78d105

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

src/start.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -542,24 +542,14 @@ async function createProxyServer(
542542
serverInstance.listen(listenPort, hostname, () => {
543543
debugLog('server', `Server listening on port ${listenPort}`, verbose)
544544

545-
if (!vitePluginUsage) {
546-
console.log('')
547-
console.log(` ${colors.green(colors.bold('rpx'))} ${colors.green(`v${version}`)}`)
548-
console.log('')
549-
console.log(` ${colors.green('➜')} ${colors.dim(from)} ${colors.dim('➜')} ${colors.cyan(ssl ? ` https://${to}` : ' http://to')}`)
550-
if (listenPort !== (ssl ? 443 : 80))
551-
console.log(` ${colors.green('➜')} Listening on port ${listenPort}`)
552-
if (ssl) {
553-
console.log(` ${colors.green('➜')} SSL enabled with:`)
554-
console.log(` - TLS 1.2/1.3`)
555-
console.log(` - Modern cipher suite`)
556-
console.log(` - HTTP/2 enabled`)
557-
console.log(` - HSTS enabled`)
558-
}
559-
if (cleanUrls) {
560-
console.log(` ${colors.green('➜')} Clean URLs enabled`)
561-
}
562-
}
545+
logToConsole({
546+
from,
547+
to,
548+
vitePluginUsage,
549+
listenPort,
550+
ssl: !!ssl,
551+
cleanUrls,
552+
})
563553

564554
resolve()
565555
})
@@ -866,3 +856,36 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
866856
}
867857
}
868858
}
859+
860+
interface OutputOptions {
861+
from?: string
862+
to?: string
863+
vitePluginUsage?: boolean
864+
listenPort?: number
865+
ssl?: boolean
866+
cleanUrls?: boolean
867+
}
868+
869+
function logToConsole(options?: OutputOptions) {
870+
if (!options?.vitePluginUsage) { // the Vite plugin handles the console output
871+
console.log('')
872+
console.log(` ${colors.green(colors.bold('rpx'))} ${colors.green(`v${version}`)}`)
873+
console.log('')
874+
console.log(` ${colors.green('➜')} ${colors.dim(options?.from)} ${colors.dim('➜')} ${colors.cyan(options?.ssl ? ` https://${options?.to}` : ` http://${options?.to}`)}`)
875+
876+
if (options?.listenPort !== (options?.ssl ? 443 : 80))
877+
console.log(` ${colors.green('➜')} Listening on port ${options?.listenPort}`)
878+
879+
if (options?.ssl) {
880+
console.log(` ${colors.green('➜')} SSL enabled with:`)
881+
console.log(` - TLS 1.2/1.3`)
882+
console.log(` - Modern cipher suite`)
883+
console.log(` - HTTP/2 enabled`)
884+
console.log(` - HSTS enabled`)
885+
}
886+
887+
if (options?.cleanUrls) {
888+
console.log(` ${colors.green('➜')} Clean URLs enabled`)
889+
}
890+
}
891+
}

0 commit comments

Comments
 (0)