Skip to content

Commit

Permalink
feat(cli): Tweak --host parameter: be even more explicit about defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
eirslett committed Apr 21, 2021
1 parent 04e0264 commit 4c22733
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ export async function preview(
)

const options = config.server || {}
const hostname = options.host || '127.0.0.1'
let hostname: string
if (options.host === undefined) {
// Use a secure default
hostname = '127.0.0.1'
} else if (options.host === true) {
// The user probably passed --host in the CLI, without arguments
hostname = '0.0.0.0'
} else {
hostname = options.host as string
}
const protocol = options.https ? 'https' : 'http'
const logger = config.logger
const base = config.base
Expand Down
14 changes: 12 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { ssrRewriteStacktrace } from '../ssr/ssrStacktrace'
import { createMissingImporterRegisterFn } from '../optimizer/registerMissing'

export interface ServerOptions {
host?: string
host?: string | boolean
port?: number
/**
* Enable TLS + HTTP/2.
Expand Down Expand Up @@ -531,7 +531,17 @@ async function startServer(

const options = server.config.server || {}
let port = inlinePort || options.port || 3000
const hostname = options.host || '127.0.0.1'
let hostname: string
if (options.host === undefined) {
// Use a secure default
hostname = '127.0.0.1'
} else if (options.host === true) {
// probably passed --host in the CLI, without arguments
hostname = '0.0.0.0'
} else {
hostname = options.host as string
}

const protocol = options.https ? 'https' : 'http'
const info = server.config.logger.info
const base = server.config.base
Expand Down

0 comments on commit 4c22733

Please sign in to comment.