fix(nuxi): show base url in terminal (#5337)

Co-authored-by: Pooya Parsa <pooya@pi0.io>
This commit is contained in:
Anthony Fu 2022-07-12 20:12:33 +08:00 committed by GitHub
parent 01700002d8
commit 100dfa6653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,7 @@ export default defineNuxtCommand({
} }
const listener = await listen(serverHandler, { const listener = await listen(serverHandler, {
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,
@ -50,6 +51,12 @@ export default defineNuxtCommand({
const { loadNuxt, buildNuxt } = await loadKit(rootDir) const { loadNuxt, buildNuxt } = await loadKit(rootDir)
let currentNuxt: Nuxt let currentNuxt: Nuxt
const showURL = () => {
listener.showURL({
// TODO: Normalize URL with trailing slash within schema
baseURL: withTrailingSlash(currentNuxt?.options.app.baseURL) || '/'
})
}
const load = async (isRestart: boolean, reason?: string) => { const load = async (isRestart: boolean, reason?: string) => {
try { try {
loadingMessage = `${reason ? reason + '. ' : ''}${isRestart ? 'Restarting' : 'Starting'} nuxt...` loadingMessage = `${reason ? reason + '. ' : ''}${isRestart ? 'Restarting' : 'Starting'} nuxt...`
@ -61,6 +68,10 @@ export default defineNuxtCommand({
await currentNuxt.close() await currentNuxt.close()
} }
currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false }) currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false })
if (!isRestart) {
showURL()
}
await currentNuxt.ready() await currentNuxt.ready()
await currentNuxt.hooks.callHook('listen', listener.server, listener) await currentNuxt.hooks.callHook('listen', listener.server, listener)
await Promise.all([ await Promise.all([
@ -70,7 +81,7 @@ export default defineNuxtCommand({
currentHandler = currentNuxt.server.app currentHandler = currentNuxt.server.app
if (isRestart && args.clear !== false) { if (isRestart && args.clear !== false) {
showBanner() showBanner()
listener.showURL() showURL()
} }
} catch (err) { } catch (err) {
consola.error(`Cannot ${isRestart ? 'restart' : 'start'} nuxt: `, err) consola.error(`Cannot ${isRestart ? 'restart' : 'start'} nuxt: `, err)