refactor: Nuxt runtimeConfig 사용하여 robots.txt 설정 개선
This commit is contained in:
@@ -9,9 +9,19 @@ type RobotsConfig = {
|
||||
}
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const host =
|
||||
(getHeader(event, 'host') || getRequestHost(event)).toString() || ''
|
||||
const baseDomain = process.env.BASE_DOMAIN
|
||||
// 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 = ''
|
||||
@@ -22,9 +32,6 @@ export default defineEventHandler(async event => {
|
||||
let config: RobotsConfig
|
||||
|
||||
try {
|
||||
const staticUrl = process.env.STATIC_URL
|
||||
const runType = process.env.RUN_TYPE
|
||||
|
||||
// gameAlias가 있을 때만 sitemap 포함
|
||||
const sitemapUrl = gameAlias
|
||||
? [`${staticUrl}/${runType}/template/${gameAlias}/sitemap.xml`]
|
||||
@@ -79,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'
|
||||
|
||||
Reference in New Issue
Block a user