Skip to content

Commit b1b816a

Browse files
bteabluwy
authored andcommitted
fix: if host is specified check whether it is valid (#14013)
1 parent 119c074 commit b1b816a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: packages/vite/src/node/cli.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ function cleanOptions<Options extends GlobalCLIOptions>(
102102
return ret
103103
}
104104

105+
/**
106+
* host may be a number (like 0), should convert to string
107+
*/
108+
const convertHost = (v: any) => {
109+
if (typeof v === 'number') {
110+
return String(v)
111+
}
112+
return v
113+
}
114+
105115
cli
106116
.option('-c, --config <file>', `[string] use specified config file`)
107117
.option('--base <path>', `[string] public base path (default: /)`)
@@ -116,7 +126,7 @@ cli
116126
.command('[root]', 'start dev server') // default command
117127
.alias('serve') // the command is called 'serve' in Vite's API
118128
.alias('dev') // alias to align with the script name
119-
.option('--host [host]', `[string] specify hostname`)
129+
.option('--host [host]', `[string] specify hostname`, { type: [convertHost] })
120130
.option('--port <port>', `[number] specify port`)
121131
.option('--https', `[boolean] use TLS + HTTP/2`)
122132
.option('--open [path]', `[boolean | string] open browser on startup`)
@@ -306,7 +316,7 @@ cli
306316
// preview
307317
cli
308318
.command('preview [root]', 'locally preview production build')
309-
.option('--host [host]', `[string] specify hostname`)
319+
.option('--host [host]', `[string] specify hostname`, { type: [convertHost] })
310320
.option('--port <port>', `[number] specify port`)
311321
.option('--strictPort', `[boolean] exit if specified port is already in use`)
312322
.option('--https', `[boolean] use TLS + HTTP/2`)

0 commit comments

Comments
 (0)