개발 서버 실행 로그 정리

This commit is contained in:
2026-05-01 23:19:21 +09:00
parent 49de0e277c
commit 18ca11f9bb
8 changed files with 98 additions and 5 deletions

75
scripts/dev-server.js Normal file
View File

@@ -0,0 +1,75 @@
import { spawn } from 'node:child_process'
const host = '127.0.0.1'
const port = '43117'
let printedLinks = false
const nuxtProcess = spawn('nuxt', [
'dev',
'--dotenv',
'.env.development',
'--host',
host,
'--port',
port
], {
shell: true,
stdio: ['inherit', 'pipe', 'pipe']
})
/**
* 개발 서버 링크 출력
* @param {string} localUrl - Nuxt 로컬 URL
* @returns {void}
*/
const printDevLinks = (localUrl) => {
const url = new URL(localUrl)
const origin = `${url.protocol}//${url.hostname}:${url.port}`
const localhostOrigin = `${url.protocol}//localhost:${url.port}`
console.log('')
console.log('sori.studio 개발 서버')
console.log(`- Localhost: ${localhostOrigin}/`)
console.log(`- Local IP: ${origin}/`)
console.log(`- Admin: ${origin}/admin`)
console.log(`- Tailwind Viewer: ${origin}/_tailwind/`)
console.log('')
}
/**
* Nuxt 로그 처리
* @param {Buffer} chunk - 로그 버퍼
* @returns {void}
*/
const handleNuxtLog = (chunk) => {
const text = chunk.toString()
for (const line of text.split('\n')) {
const localMatch = line.match(/Local:\s+(https?:\/\/[^\s]+)/)
if (localMatch && !printedLinks) {
printedLinks = true
printDevLinks(localMatch[1])
continue
}
if (/(^|\s)(error:|warn:|warning:|failed|fatal|eaddrinuse|cannot)\b/i.test(line)) {
console.log(line)
}
}
}
nuxtProcess.stdout.on('data', handleNuxtLog)
nuxtProcess.stderr.on('data', handleNuxtLog)
nuxtProcess.on('close', (code) => {
process.exit(code || 0)
})
process.on('SIGINT', () => {
nuxtProcess.kill('SIGINT')
})
process.on('SIGTERM', () => {
nuxtProcess.kill('SIGTERM')
})