Skip to content

Commit 24596a4

Browse files
committed
chore: more SSL work
1 parent 21b4ff6 commit 24596a4

6 files changed

+10
-9
lines changed

bun.lockb

-4.69 KB
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"preview:docs": "vitepress preview docs"
6262
},
6363
"dependencies": {
64-
"@stacksjs/tlsx": "^0.4.3"
64+
"@stacksjs/tlsx": "^0.5.6"
6565
},
6666
"devDependencies": {
6767
"@stacksjs/cli": "^0.68.2",

reverse-proxy.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const config: ReverseProxyOptions = {
99
// certPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.crt`),
1010
// caCertPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.ca.crt`),
1111
https: true,
12-
verbose: false,
12+
verbose: true,
1313
}
1414

1515
export default config

src/certificate.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { log } from '@stacksjs/cli'
44
import { addCertToSystemTrustStoreAndSaveCert, createRootCA, generateCert } from '@stacksjs/tlsx'
55
import { config } from './config'
66

7-
export async function generateCertficate(options?: TlsOption): Promise<{ key: string, cert: string, ca: string }> {
7+
export async function generateCertificate(options?: TlsOption): Promise<{ key: string, cert: string, ca: string }> {
88
const conf = config?.tls
99
const mergedOptions = {
1010
...conf,
@@ -14,7 +14,7 @@ export async function generateCertficate(options?: TlsOption): Promise<{ key: st
1414
const domain = mergedOptions.domain || 'localhost'
1515
log.info(`Generating a self-signed SSL certificate for: ${domain}`)
1616

17-
const caCert = await createRootCA()
17+
const caCert = await createRootCA(mergedOptions)
1818
const hostCert = await generateCert({
1919
hostCertCN: mergedOptions?.commonName ?? mergedOptions.commonName ?? domain,
2020
domain,
@@ -29,9 +29,10 @@ export async function generateCertficate(options?: TlsOption): Promise<{ key: st
2929
certificate: caCert.certificate,
3030
privateKey: caCert.privateKey,
3131
},
32+
verbose: mergedOptions.verbose,
3233
})
3334

34-
await addCertToSystemTrustStoreAndSaveCert(hostCert, caCert.certificate)
35+
await addCertToSystemTrustStoreAndSaveCert(hostCert, caCert.certificate, mergedOptions)
3536

3637
log.success('Certificate generated')
3738

src/start.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as net from 'node:net'
99
import process from 'node:process'
1010
import { bold, dim, green, log } from '@stacksjs/cli'
1111
import { version } from '../package.json'
12-
import { generateCertficate } from './certificate'
12+
import { generateCertificate } from './certificate'
1313
import { config } from './config'
1414
import { debugLog } from './utils'
1515

@@ -123,7 +123,7 @@ async function loadSSLConfig(options: ReverseProxyOption): Promise<SSLConfig | n
123123
// If HTTPS is true but no certificates provided at all, generate certificate
124124
if (options.https === true) {
125125
debugLog('ssl', 'Generating self-signed certificate')
126-
return await generateCertficate(options)
126+
return await generateCertificate(options.tls)
127127
}
128128

129129
// Default to no SSL
@@ -209,7 +209,7 @@ export async function startServer(options?: ReverseProxyOption): Promise<void> {
209209
...config,
210210
...(options || {}),
211211
}
212-
212+
debugLog('server', `Merged options: ${JSON.stringify(mergedOptions)}`)
213213
const { fromUrl, toUrl, protocol } = normalizeUrls(mergedOptions)
214214
const fromPort = Number.parseInt(fromUrl.port) || (protocol.includes('https:') ? 443 : 80)
215215

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface ReverseProxyConfig {
99
certPath?: string // absolute path to the cert
1010
caCertPath?: string // absolute path to the ca cert
1111
https: boolean // use https, defaults to true
12-
tls: boolean | TlsConfig // the tls configuration
12+
tls: TlsConfig // the tls configuration
1313
verbose: boolean
1414
}
1515

0 commit comments

Comments
 (0)