File tree Expand file tree Collapse file tree 3 files changed +8
-2
lines changed
Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ export default {
1717 name: ' test' ,
1818 /** custom trust domains */
1919 domains: [' *.custom.com' ],
20+ /** optional, days before certificate expires */
21+ ttlDays: 30 ,
2022 /** custom certification directory */
2123 certDir: ' /Users/.../.devServer/cert' ,
2224 }),
Original file line number Diff line number Diff line change @@ -55,8 +55,8 @@ function toPositiveHex(hexString: string) {
5555export function createCertificate (
5656 name : string = 'example.org' ,
5757 domains ?: string [ ] ,
58+ ttlDays = 30 ,
5859) : string {
59- const days = 30
6060 const keySize = 2048
6161
6262 const appendDomains = domains
@@ -146,7 +146,7 @@ export function createCertificate(
146146
147147 cert . validity . notBefore = new Date ( )
148148 cert . validity . notAfter = new Date ( )
149- cert . validity . notAfter . setDate ( cert . validity . notBefore . getDate ( ) + days )
149+ cert . validity . notAfter . setDate ( cert . validity . notBefore . getDate ( ) + ttlDays )
150150
151151 cert . setSubject ( attrs )
152152 cert . setIssuer ( attrs )
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ interface Options {
88 certDir : string
99 domains : string [ ]
1010 name : string
11+ ttlDays : number
1112}
1213
1314function viteBasicSslPlugin ( options ?: Partial < Options > ) : Plugin {
@@ -18,6 +19,7 @@ function viteBasicSslPlugin(options?: Partial<Options>): Plugin {
1819 options ?. certDir ?? ( config . cacheDir ?? defaultCacheDir ) + '/basic-ssl' ,
1920 options ?. name ,
2021 options ?. domains ,
22+ options ?. ttlDays ,
2123 )
2224 const https = ( ) => ( { cert : certificate , key : certificate } )
2325 if ( config . server . https === undefined || ! ! config . server . https ) {
@@ -34,6 +36,7 @@ export async function getCertificate(
3436 cacheDir : string ,
3537 name ?: string ,
3638 domains ?: string [ ] ,
39+ ttlDays ?: number ,
3740) {
3841 const cachePath = path . join ( cacheDir , '_cert.pem' )
3942
@@ -52,6 +55,7 @@ export async function getCertificate(
5255 const content = ( await import ( './certificate' ) ) . createCertificate (
5356 name ,
5457 domains ,
58+ ttlDays ,
5559 )
5660 fsp
5761 . mkdir ( cacheDir , { recursive : true } )
You can’t perform that action at this time.
0 commit comments