fix(nuxi): read devServer options from nuxt config (#19055)

This commit is contained in:
Hamish Claxton 2023-02-16 23:17:56 +10:00 committed by GitHub
parent 681cfa83fd
commit c45b842037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View File

@ -44,20 +44,27 @@ export default defineNuxtCommand({
await setupDotenv({ cwd: rootDir, fileName: args.dotenv }) await setupDotenv({ cwd: rootDir, fileName: args.dotenv })
const { loadNuxt, loadNuxtConfig, buildNuxt } = await loadKit(rootDir)
const config = await loadNuxtConfig({
cwd: rootDir,
overrides: { dev: true }
})
const listener = await listen(serverHandler, { const listener = await listen(serverHandler, {
showURL: false, showURL: false,
clipboard: args.clipboard, clipboard: args.clipboard,
open: args.open || args.o, open: args.open || args.o,
port: args.port || args.p || process.env.NUXT_PORT, port: args.port || args.p || process.env.NUXT_PORT || config.devServer.port,
hostname: args.host || args.h || process.env.NUXT_HOST, hostname: args.host || args.h || process.env.NUXT_HOST || config.devServer.host,
https: args.https && { https: (args.https !== false && (args.https || config.devServer.https))
cert: args['ssl-cert'], ? {
key: args['ssl-key'] cert: args['ssl-cert'] || (config.devServer.https && config.devServer.https.cert) || undefined,
} key: args['ssl-key'] || (config.devServer.https && config.devServer.https.key) || undefined
}
: false
}) })
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
let currentNuxt: Nuxt let currentNuxt: Nuxt
const showURL = () => { const showURL = () => {
listener.showURL({ listener.showURL({

View File

@ -28,10 +28,13 @@ export default defineUntypedSchema({
port: process.env.NUXT_PORT || process.env.NITRO_PORT || process.env.PORT || 3000, port: process.env.NUXT_PORT || process.env.NITRO_PORT || process.env.PORT || 3000,
/** Dev server listening host */ /** Dev server listening host */
host: process.env.NUXT_HOST || process.env.NITRO_HOST || process.env.HOST || 'localhost', host: process.env.NUXT_HOST || process.env.NITRO_HOST || process.env.HOST || '',
/** /**
* Listening dev server url * Listening dev server URL.
*
* This should not be set directly as it will always be overridden by the
* dev server with the full URL (for module and internal use).
*/ */
url: 'http://localhost:3000', url: 'http://localhost:3000',
} }