Skip to content

Commit

Permalink
chore: refactor to logToConsole
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Jan 28, 2025
1 parent 94089f5 commit 1936130
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,24 +542,7 @@ async function createProxyServer(
serverInstance.listen(listenPort, hostname, () => {
debugLog('server', `Server listening on port ${listenPort}`, verbose)

if (!vitePluginUsage) {
console.log('')
console.log(` ${colors.green(colors.bold('rpx'))} ${colors.green(`v${version}`)}`)
console.log('')
console.log(` ${colors.green('➜')} ${colors.dim(from)} ${colors.dim('➜')} ${colors.cyan(ssl ? ` https://${to}` : ' http://to')}`)
if (listenPort !== (ssl ? 443 : 80))
console.log(` ${colors.green('➜')} Listening on port ${listenPort}`)
if (ssl) {
console.log(` ${colors.green('➜')} SSL enabled with:`)
console.log(` - TLS 1.2/1.3`)
console.log(` - Modern cipher suite`)
console.log(` - HTTP/2 enabled`)
console.log(` - HSTS enabled`)
}
if (cleanUrls) {
console.log(` ${colors.green('➜')} Clean URLs enabled`)
}
}
logToConsole()

resolve()
})
Expand Down Expand Up @@ -866,3 +849,36 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
}
}
}

interface OutputOptions {
from?: string
to?: string
vitePluginUsage?: boolean
listenPort?: number
ssl?: boolean
cleanUrls?: boolean
}

function logToConsole(options?: OutputOptions) {
if (!options?.vitePluginUsage) { // the Vite plugin handles the console output
console.log('')
console.log(` ${colors.green(colors.bold('rpx'))} ${colors.green(`v${version}`)}`)
console.log('')
console.log(` ${colors.green('➜')} ${colors.dim(options?.from)} ${colors.dim('➜')} ${colors.cyan(options?.ssl ? ` https://${options?.to}` : ` http://${options?.to}`)}`)

if (options?.listenPort !== (options?.ssl ? 443 : 80))
console.log(` ${colors.green('➜')} Listening on port ${options?.listenPort}`)

if (options?.ssl) {
console.log(` ${colors.green('➜')} SSL enabled with:`)
console.log(` - TLS 1.2/1.3`)
console.log(` - Modern cipher suite`)
console.log(` - HTTP/2 enabled`)
console.log(` - HSTS enabled`)
}

if (options?.cleanUrls) {
console.log(` ${colors.green('➜')} Clean URLs enabled`)
}
}
}

0 comments on commit 1936130

Please sign in to comment.