Merge branch 'feature/20260327_gil_nitroLog' into feature/20260331_all

This commit is contained in:
“hyeonggkim”
2026-03-31 17:13:46 +09:00
9 changed files with 502 additions and 26 deletions

View File

@@ -19,7 +19,7 @@ export default defineNitroPlugin(nitroApp => {
// 헬스체크 경로 체크 함수 추가
const isHealthCheck = (path: string): boolean => {
return path === '/health'
return path === '/health' || path === '/api/healthz'
}
nitroApp.hooks.hook('request', event => {
@@ -33,22 +33,23 @@ export default defineNitroPlugin(nitroApp => {
const method = event.method || ''
const headers = JSON.stringify(event.node.req.headers, null, 2)
const requestId = generateRequestId()
const domain = event.node.req.headers.host || 'unknown'
if (process.env.NODE_ENV !== 'development') {
// if (process.env.NODE_ENV !== 'development') {
console.log(
`Request Info {"requestId":"${requestId}", "type":"request","method":"${method}","url":"${event.path}","userIp":"${getIpAddress(event)}","userAgent":"${userAgent}", "headers" : "${headers}" }`
`Request Info {"requestId":"${requestId}", "type":"request","method":"${method}","domain":"${domain}","url":"${event.path}","userIp":"${getIpAddress(event)}","userAgent":"${userAgent}", "headers" : "${headers}" }`
)
// 요청 완료 후 응답 상태 코드 로깅
event.node.res.on('finish', () => {
console.log(
`Response Info {"requestId":"${requestId}","type":"response","method":"${method}","url":"${event.path}","statusCode":${event.node.res.statusCode},"responseTime":"${Date.now() - startTime}ms","userIp":"${getIpAddress(event)}","userAgent":"${userAgent}","statusMessage":"${event.node.res.statusMessage}","responseHeader": ${JSON.stringify(event.node.res.getHeaders(), null, 2)}}`
`Response Info {"requestId":"${requestId}","type":"response","method":"${method}","domain":"${domain}","url":"${event.path}","statusCode":${event.node.res.statusCode},"responseTime":"${Date.now() - startTime}ms","userIp":"${getIpAddress(event)}","userAgent":"${userAgent}","statusMessage":"${event.node.res.statusMessage}","responseHeader": ${JSON.stringify(event.node.res.getHeaders(), null, 2)}}`
)
console.log(
'==========================================================================================================================================================================================================================================================='
)
})
}
// }
})
nitroApp.hooks.hook('error', error => {

View File

@@ -9,34 +9,40 @@ type RobotsConfig = {
}
export default defineEventHandler(async event => {
const host =
(getHeader(event, 'host') || getRequestHost(event)).toString() || ''
const baseDomain = process.env.BASE_DOMAIN || '.onstove.com'
// Nuxt runtimeConfig 사용
const runtimeConfig = useRuntimeConfig()
const baseDomain = runtimeConfig.public.baseDomain
const staticUrl = runtimeConfig.public.staticUrl
const runType = runtimeConfig.public.runType
// 프록시 뒤에 있는 경우 X-Forwarded-Host 우선 사용
const forwardedHost = getHeader(event, 'x-forwarded-host')
const host = (
forwardedHost ||
getHeader(event, 'host') ||
getRequestHost(event)
).toString() || ''
const isGameAliasExtractable = host.includes(baseDomain)
let gameAlias = ''
if (isGameAliasExtractable) {
gameAlias = host.split('.')[0]
gameAlias = host.split('.')[0].replace(/-dev$/, '')
}
// if (gameAlias && gameAlias !== "www") {
// event.context.gameAlias = gameAlias;
// }
// }
// robots 설정을 직접 가져오기 (미들웨어 context 사용)
let config: RobotsConfig
try {
// robots 설정 추출
// gameAlias가 있을 때만 sitemap 포함
const sitemapUrl = gameAlias
? [`${staticUrl}/${runType}/template/${gameAlias}/sitemap.xml`]
: undefined
config = {
userAgent: '*',
allow: ['/'],
disallow: ['/error', '/inspection/', '/inspection/*', '/html/*'],
sitemap: [
`https://static-pubcomm.gate8.com/local/template/${gameAlias}/sitemap.xml`,
],
host: `${gameAlias}.onstove.com`,
disallow: ['/error', '/inspection/*', '/html/*'],
sitemap: sitemapUrl,
host: gameAlias ? `${gameAlias}.onstove.com` : undefined,
cache: { sMaxAge: 300, staleWhileRevalidate: 600 },
}
} catch (error) {
@@ -46,7 +52,7 @@ export default defineEventHandler(async event => {
config = {
userAgent: '*',
allow: ['/'],
disallow: ['/error', '/inspection/', '/inspection/*', '/html/*'],
disallow: ['/error', '/inspection/*', '/html/*'],
cache: { sMaxAge: 300, staleWhileRevalidate: 600 },
}
}
@@ -80,8 +86,14 @@ export default defineEventHandler(async event => {
: config.sitemap
? [config.sitemap]
: []
for (const sm of sitemaps) lines.push(`Sitemap: ${sm}`)
if (config.host) lines.push(`Host: ${config.host}`)
for (const sm of sitemaps) {
lines.push(`Sitemap: ${sm}`)
}
if (config.host) {
lines.push(`Host: ${config.host}`)
}
// 마지막 개행
return lines.join('\n').trim() + '\n'