Skip to content

Commit

Permalink
feat: allow for vite plugin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Dec 13, 2024
1 parent a8566e0 commit 64d7852
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const defaultConfig: ReverseProxyConfig = {
keyPath: join(homedir(), '.stacks', 'ssl', `stacks.localhost.crt.key`),
},
etcHostsCleanup: true,
vitePluginUsage: false,
verbose: true,
}

Expand Down
37 changes: 22 additions & 15 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ async function createProxyServer(
hostname: string,
sourceUrl: Pick<URL, 'hostname' | 'host'>,
ssl: SSLConfig | null,
vitePluginUsage?: boolean,
verbose?: boolean,
cleanUrls?: boolean,
): Promise<void> {
Expand Down Expand Up @@ -450,21 +451,23 @@ async function createProxyServer(
server.listen(listenPort, hostname, () => {
debugLog('server', `Server listening on port ${listenPort}`, verbose)

console.log('')
console.log(` ${green(bold('reverse-proxy'))} ${green(`v${version}`)}`)
console.log('')
console.log(` ${green('➜')} ${dim(from)} ${dim('➜')} ${ssl ? 'https' : 'http'}://${to}`)
if (listenPort !== (ssl ? 443 : 80))
console.log(` ${green('➜')} Listening on port ${listenPort}`)
if (ssl) {
console.log(` ${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(` ${green('➜')} Clean URLs enabled`)
if (!vitePluginUsage) {
console.log('')
console.log(` ${green(bold('reverse-proxy'))} ${green(`v${version}`)}`)
console.log('')
console.log(` ${green('➜')} ${dim(from)} ${dim('➜')} ${ssl ? 'https' : 'http'}://${to}`)
if (listenPort !== (ssl ? 443 : 80))
console.log(` ${green('➜')} Listening on port ${listenPort}`)
if (ssl) {
console.log(` ${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(` ${green('➜')} Clean URLs enabled`)
}
}

resolve()
Expand Down Expand Up @@ -562,6 +565,7 @@ export function startProxy(options: ReverseProxyOption): void {
cleanUrls: mergedOptions.cleanUrls,
https: httpsConfig(mergedOptions),
etcHostsCleanup: mergedOptions.etcHostsCleanup,
vitePluginUsage: mergedOptions.vitePluginUsage,
verbose: mergedOptions.verbose,
}

Expand Down Expand Up @@ -620,6 +624,7 @@ export async function startProxies(options?: ReverseProxyOptions): Promise<void>
https: mergedOptions.https,
etcHostsCleanup: mergedOptions.etcHostsCleanup,
cleanUrls: mergedOptions.cleanUrls,
vitePluginUsage: mergedOptions.vitePluginUsage,
verbose: mergedOptions.verbose,
_cachedSSLConfig: mergedOptions._cachedSSLConfig,
}))
Expand All @@ -629,6 +634,7 @@ export async function startProxies(options?: ReverseProxyOptions): Promise<void>
cleanUrls: mergedOptions.cleanUrls || false,
https: mergedOptions.https,
etcHostsCleanup: mergedOptions.etcHostsCleanup,
vitePluginUsage: mergedOptions.vitePluginUsage,
verbose: mergedOptions.verbose,
_cachedSSLConfig: mergedOptions._cachedSSLConfig,
}]
Expand Down Expand Up @@ -665,6 +671,7 @@ export async function startProxies(options?: ReverseProxyOptions): Promise<void>
cleanUrls: option.cleanUrls || false,
https: option.https || false,
etcHostsCleanup: option.etcHostsCleanup || false,
vitePluginUsage: option.vitePluginUsage || false,
verbose: option.verbose || false,
_cachedSSLConfig: sslConfig,
})
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CleanupOptions {
export interface SharedProxyConfig {
https: boolean | TlsOption
etcHostsCleanup: boolean
vitePluginUsage: boolean
verbose: boolean
_cachedSSLConfig?: SSLConfig | null
}
Expand Down

0 comments on commit 64d7852

Please sign in to comment.