Skip to content

Commit

Permalink
fix(preview): allow to disable HTTPS (#3514)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed May 23, 2021
1 parent 5979d0e commit cf1632e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ cli
.command('preview [root]')
.option('--host [host]', `[string] specify hostname`)
.option('--port <port>', `[number] specify port`)
.option('--https', `[boolean] use TLS + HTTP/2`)
.option('--open [path]', `[boolean | string] open browser on startup`)
.action(
async (
root: string,
options: {
host?: string
port?: number
https?: boolean
open?: boolean | string
} & GlobalCLIOptions
) => {
Expand All @@ -212,7 +214,14 @@ cli
'serve',
'development'
)
await preview(config, { host: options.host, port: options.port })
await preview(
config,
cleanOptions(options) as {
host?: string
port?: number
https?: boolean
}
)
} catch (e) {
createLogger(options.logLevel).error(
chalk.red(`error when starting preview server:\n${e.stack}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { resolveHostname } from './utils'

export async function preview(
config: ResolvedConfig,
serverOptions: { host?: string; port?: number }
serverOptions: { host?: string; port?: number; https?: boolean }
): Promise<void> {
const app = connect() as Connect.Server
const httpServer = await resolveHttpServer(
config.server,
app,
await resolveHttpsConfig(config)
serverOptions.https === false ? undefined : await resolveHttpsConfig(config)
)

// cors
Expand Down

0 comments on commit cf1632e

Please sign in to comment.