고정 페이지 HTML 문서 모드 추가 v1.5.1

This commit is contained in:
2026-05-26 11:03:33 +09:00
parent 0ad2ab3f9d
commit a25306389b
15 changed files with 169 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
import { getMethod, getRequestURL, setResponseHeader } from 'h3'
import { getPageBySlug } from '../repositories/content-repository'
/**
* 공개 페이지가 HTML 문서 모드일 때 Nuxt 렌더링 대신 원문 HTML을 응답한다.
* @param {import('h3').H3Event} event - 요청 이벤트
* @returns {Promise<string | void>} HTML 문서 또는 다음 핸들러 진행
*/
export default defineEventHandler(async (event) => {
const method = getMethod(event)
if (method !== 'GET' && method !== 'HEAD') {
return
}
const pathname = getRequestURL(event).pathname
const match = pathname.match(/^\/pages\/([^/]+)\/?$/)
if (!match) {
return
}
const slug = decodeURIComponent(match[1])
const page = await getPageBySlug(slug)
if (page?.renderMode !== 'html_document') {
return
}
setResponseHeader(event, 'content-type', 'text/html; charset=utf-8')
setResponseHeader(event, 'cache-control', 'no-cache')
return page.content || ''
})