-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcms.mts
28 lines (21 loc) · 893 Bytes
/
cms.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { getDeployStore } from '@netlify/blobs'
import { Context } from '@netlify/functions'
// publish or unpublish "cms content" depending on the sent operation
export default async function handler(_request: Request, context: Context) {
const store = getDeployStore({ name: 'cms-content', consistency: 'strong' })
const operation = context.params['operation']
// root of optional catch-all route in Next.js sets 'index.html' as param
// while it's undefined in the Netlify function, because we need to declare
// path without wildcard
const contentKey = context.params['0'] ?? 'index.html'
if (operation === 'publish') {
await store.setJSON(contentKey, { content: true })
}
if (operation === 'unpublish') {
await store.delete(contentKey)
}
return Response.json({ ok: true })
}
export const config = {
path: ['/cms/:operation/*', '/cms/:operation'],
}