사이트 코드와 홈페이지 위젯 추가 v1.5.34
This commit is contained in:
26
server/routes/ads.txt.get.js
Normal file
26
server/routes/ads.txt.get.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { setHeader } from 'h3'
|
||||
import { getSiteSettings } from '../repositories/content-repository'
|
||||
|
||||
/**
|
||||
* ads.txt 본문을 정규화한다.
|
||||
* @param {string} value - 관리자 설정에 저장된 ads.txt 본문
|
||||
* @returns {string} text/plain 응답 본문
|
||||
*/
|
||||
const normalizeAdsTxt = (value) => {
|
||||
const text = String(value || '').trim()
|
||||
|
||||
return text ? `${text}\n` : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 루트 ads.txt 응답
|
||||
* @param {import('h3').H3Event} event - 요청 이벤트
|
||||
* @returns {Promise<string>} ads.txt 본문
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
setHeader(event, 'Content-Type', 'text/plain; charset=utf-8')
|
||||
|
||||
const settings = await getSiteSettings()
|
||||
|
||||
return normalizeAdsTxt(settings.adsTxt)
|
||||
})
|
||||
Reference in New Issue
Block a user