Skip to content

Commit

Permalink
chore: update readme and fix test type error
Browse files Browse the repository at this point in the history
  • Loading branch information
gz65555 committed Jan 11, 2024
1 parent 5806239 commit 35696cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import basicSsl from '@vitejs/plugin-basic-ssl'

export default {
plugins: [
basicSsl()
basicSsl({
/** name of certification */
name: 'test',
/** custom trust domains */
domains: ['*.custom.com'],
/** custom certification directory */
certDir: '/Users/.../.devServer/cert'
})
]
}
```

## License

MIT
2 changes: 1 addition & 1 deletion src/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function toPositiveHex(hexString: string) {
return mostSignificativeHexAsInt.toString() + hexString.substring(1)
}

export function createCertificate(name: string, domains?: string[]): string {
export function createCertificate(name: string = 'example.org', domains?: string[]): string {
const days = 30
const keySize = 2048

Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { promises as fsp } from 'node:fs'
import type { Plugin } from 'vite'

const defaultCacheDir = 'node_modules/.vite'
const defaultName = 'example.org'

interface Options {
certDir: string
Expand All @@ -17,7 +16,7 @@ function viteBasicSslPlugin(options?: Partial<Options>): Plugin {
async configResolved(config) {
const certificate = await getCertificate(
options?.certDir ?? (config.cacheDir ?? defaultCacheDir) + '/basic-ssl',
options?.name ?? defaultName,
options?.name,
options?.domains
)
const https = () => ({ cert: certificate, key: certificate })
Expand All @@ -29,7 +28,7 @@ function viteBasicSslPlugin(options?: Partial<Options>): Plugin {

export async function getCertificate(
cacheDir: string,
name: string,
name?: string,
domains?: string[]
) {
const cachePath = path.join(cacheDir, '_cert.pem')
Expand Down

0 comments on commit 35696cb

Please sign in to comment.