New SiteContent.
This commit is contained in:
parent
02222a5c16
commit
7e7672d52b
5 changed files with 285 additions and 0 deletions
18
server/api/site-content/[key].get.js
Normal file
18
server/api/site-content/[key].get.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import SiteContent from '../../models/siteContent.js'
|
||||
import { SITE_CONTENT_KEYS } from '../../utils/schemas.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const key = getRouterParam(event, 'key')
|
||||
|
||||
if (!SITE_CONTENT_KEYS.includes(key)) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Unknown content key' })
|
||||
}
|
||||
|
||||
const doc = await SiteContent.findOne({ key }).lean()
|
||||
return {
|
||||
key,
|
||||
title: doc?.title || '',
|
||||
body: doc?.body || '',
|
||||
updatedAt: doc?.updatedAt || null
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue