fix: a
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
const VALID_DOCS = ['imprint', 'privacy-policy']
|
||||
const VALID_LOCALES = ['en', 'de']
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const doc = getRouterParam(event, 'doc')
|
||||
const query = getQuery(event)
|
||||
const lang = typeof query.lang === 'string' && VALID_LOCALES.includes(query.lang)
|
||||
? query.lang
|
||||
: 'en'
|
||||
|
||||
if (!doc || !VALID_DOCS.includes(doc)) {
|
||||
throw createError({ statusCode: 404, message: `Unknown legal document: "${doc}". Valid options: ${VALID_DOCS.join(', ')}` })
|
||||
}
|
||||
|
||||
const locales = lang === 'en' ? ['en'] : [lang, 'en']
|
||||
|
||||
for (const locale of locales) {
|
||||
const filePath = resolve(process.cwd(), `content/${locale}/${doc}.md`)
|
||||
try {
|
||||
const content = await readFile(filePath, 'utf-8')
|
||||
return { locale, doc, content }
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
|
||||
throw createError({ statusCode: 404, message: `Legal document "${doc}" not found` })
|
||||
})
|
||||
Reference in New Issue
Block a user