File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 11import { Client } from '@notionhq/client'
2- import { defineNuxtPlugin , useRuntimeConfig } from '#app'
2+ import type { Ref } from 'vue'
3+ import { defineNuxtPlugin , useAsyncData , useRuntimeConfig } from '#app'
34
45export default defineNuxtPlugin ( {
56 name : 'nuxt-notion-cms' ,
67 enforce : 'pre' ,
78 async setup ( ) {
8- const config = useRuntimeConfig ( ) . public . notion
9+ const config = useRuntimeConfig ( ) . notion
10+
11+ const notionFetch = $fetch . create ( {
12+ baseURL : config . apiBase ,
13+ } )
914
1015 const client = new Client ( {
1116 ...config ,
1217 auth : 'custom-auth-token' ,
18+ fetch : async ( url , params ) => {
19+ const urlSlug = url . replace ( 'https://api.notion.com/v1' , '' )
20+
21+ const res = await useAsyncData ( urlSlug , ( ) => notionFetch ( urlSlug ) , {
22+ server : true ,
23+ getCachedData ( key , nuxtApp ) {
24+ const data : Ref < unknown > = nuxtApp . payload . data [ key ] || nuxtApp . static . data [ key ]
25+ return data
26+ } ,
27+ } )
28+
29+ const data = res . data . value as unknown
30+
31+ const response = new Response ( JSON . stringify ( data ) , params )
32+
33+ return response
34+ } ,
1335 } )
1436
1537 return {
You can’t perform that action at this time.
0 commit comments