feat(nuxi): support --host, --ssl-cert, and --ssl-key args (#993)

This commit is contained in:
Levi (Nguyễn Lương Huy) 2021-10-14 18:36:04 +07:00 committed by GitHub
parent b2c74d739f
commit 0b45721b8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,16 +12,25 @@ import { defineNuxtCommand } from './index'
export default defineNuxtCommand({ export default defineNuxtCommand({
meta: { meta: {
name: 'dev', name: 'dev',
usage: 'npx nuxi dev [rootDir] [--clipboard] [--open, -o]', usage: 'npx nuxi dev [rootDir] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--ssl-cert] [--ssl-key]',
description: 'Run nuxt development server' description: 'Run nuxt development server'
}, },
async invoke (args) { async invoke (args) {
process.env.NODE_ENV = process.env.NODE_ENV || 'development' process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const https = !!(args['ssl-cert'] && args['ssl-key'])
const server = createServer() const server = createServer()
const listener = await server.listen({ const listener = await server.listen({
clipboard: args.clipboard, clipboard: args.clipboard,
open: args.open || args.o, open: args.open || args.o,
port: args.port || args.p port: args.port || args.p,
hostname: args.host || args.h,
...(https && {
https,
certificate: {
cert: args['ssl-cert'],
key: args['ssl-key']
}
})
}) })
const rootDir = resolve(args._[0] || '.') const rootDir = resolve(args._[0] || '.')