Skip to content

Commit

Permalink
feat: support read host from server config
Browse files Browse the repository at this point in the history
  • Loading branch information
liuweiGL committed Aug 1, 2021
1 parent 3695e8c commit 305639b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ const plugin = (options: ViteCertificateOptions = {}): Plugin => {
return {
name: PLUGIN_NAME,
apply: 'serve',
config: async config => {
if (!config.server?.https) {
config: async ({ server, logLevel }) => {
if (!server?.https) {
return
}

const { hosts = getDefaultHosts(), ...mkcertOptions } = options

const { logLevel } = config
const logger = createLogger(logLevel, {
prefix: PLUGIN_NAME
})
Expand All @@ -35,7 +34,9 @@ const plugin = (options: ViteCertificateOptions = {}): Plugin => {

await mkcert.init()

const uniqueHosts = Array.from(new Set(hosts))
const allHosts =
typeof server.host === 'string' ? [...hosts, server.host] : hosts
const uniqueHosts = Array.from(new Set(allHosts)).filter(item => !!item)
const certificate = await mkcert.install(uniqueHosts)

return {
Expand Down

0 comments on commit 305639b

Please sign in to comment.