Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default {
name: 'test',
/** custom trust domains */
domains: ['*.custom.com'],
/** optional, days before certificate expires */
ttlDays: 30,
/** custom certification directory */
certDir: '/Users/.../.devServer/cert',
}),
Expand Down
4 changes: 2 additions & 2 deletions src/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function toPositiveHex(hexString: string) {
export function createCertificate(
name: string = 'example.org',
domains?: string[],
ttlDays = 30,
): string {
const days = 30
const keySize = 2048

const appendDomains = domains
Expand Down Expand Up @@ -146,7 +146,7 @@ export function createCertificate(

cert.validity.notBefore = new Date()
cert.validity.notAfter = new Date()
cert.validity.notAfter.setDate(cert.validity.notBefore.getDate() + days)
cert.validity.notAfter.setDate(cert.validity.notBefore.getDate() + ttlDays)

cert.setSubject(attrs)
cert.setIssuer(attrs)
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Options {
certDir: string
domains: string[]
name: string
ttlDays: number
}

function viteBasicSslPlugin(options?: Partial<Options>): Plugin {
Expand All @@ -18,6 +19,7 @@ function viteBasicSslPlugin(options?: Partial<Options>): Plugin {
options?.certDir ?? (config.cacheDir ?? defaultCacheDir) + '/basic-ssl',
options?.name,
options?.domains,
options?.ttlDays,
)
const https = () => ({ cert: certificate, key: certificate })
if (config.server.https === undefined || !!config.server.https) {
Expand All @@ -34,6 +36,7 @@ export async function getCertificate(
cacheDir: string,
name?: string,
domains?: string[],
ttlDays?: number,
) {
const cachePath = path.join(cacheDir, '_cert.pem')

Expand All @@ -52,6 +55,7 @@ export async function getCertificate(
const content = (await import('./certificate')).createCertificate(
name,
domains,
ttlDays,
)
fsp
.mkdir(cacheDir, { recursive: true })
Expand Down