-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move fetching global data from craft to server apis and use nitr…
…o storage in these files to set and get
- Loading branch information
Showing
13 changed files
with
233 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
export default defineNuxtPlugin(async (nuxtApp) => { // | ||
/* console.log( | ||
'this is called only once during build time and should not run on every page load', | ||
) */ | ||
console.log('init.server.js start') | ||
const craftGlobals = useGlobalStore(nuxtApp.$pinia) // | ||
await craftGlobals.fetchGlobals() | ||
await craftGlobals.fetchHeader() | ||
await craftGlobals.fetchFooterPrimary() | ||
await craftGlobals.fetchFooterSock() | ||
console.log('init.server.js end') | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
const MenuItem = ` | ||
id | ||
name: title | ||
to: url | ||
classes | ||
target: newWindow | ||
` | ||
const footerPrimaryQuery = ` | ||
query FooterPrimaryItems { | ||
nodes(navHandle: "footerPrimary", level: 1) { | ||
${MenuItem} | ||
children { | ||
${MenuItem} | ||
} | ||
} | ||
} | ||
` | ||
export default cachedEventHandler(async () => { | ||
return await useStorage().getItem('craftData:footerPrimary') | ||
const endpoint = useRuntimeConfig().public.craftGraphqlURL | ||
let footerPrimaryData = await useStorage().getItem('craftData:footerPrimary') | ||
console.log('Server api Craft Footer primary Data object:' + JSON.stringify(footerPrimaryData)) | ||
if (!footerPrimaryData) { | ||
const { data } = await $fetch(endpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ query: footerPrimaryQuery }) | ||
}) | ||
await useStorage().setItem('craftData:footerPrimary', data) | ||
footerPrimaryData = await useStorage().getItem('craftData:footerPrimary') | ||
console.log('Server api Craft Footer primary Data object first set and then get:' + JSON.stringify(footerPrimaryData)) | ||
} | ||
return footerPrimaryData | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
const MenuItem = ` | ||
id | ||
name: title | ||
to: url | ||
classes | ||
target: newWindow | ||
` | ||
const footerSockQuery = ` | ||
query FooterSockItems { | ||
nodes(navHandle: "footerSockLinks") { | ||
${MenuItem} | ||
} | ||
} | ||
` | ||
|
||
export default cachedEventHandler(async () => { | ||
return await useStorage().getItem('craftData:footerSock') | ||
const endpoint = useRuntimeConfig().public.craftGraphqlURL | ||
let footerSockData = await useStorage().getItem('craftData:footerSock') | ||
console.log('Server api Craft Footer sock Data object:' + JSON.stringify(footerSockData)) | ||
if (!footerSockData) { | ||
const { data } = await $fetch(endpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ query: footerSockQuery }) | ||
}) | ||
await useStorage().setItem('craftData:footerSock', data) | ||
footerSockData = await useStorage().getItem('craftData:footerSock') | ||
console.log('Server api Craft Footer sock Data object first set and then get:' + JSON.stringify(footerSockData)) | ||
} | ||
return footerSockData | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
const globalsQuery = ` | ||
query Globals { | ||
globalSets { | ||
dataId: id | ||
handle | ||
... on askALibrarian_GlobalSet { | ||
askALibrarianTitle: titleGeneral | ||
askALibrarianText: summary | ||
buttonUrl { | ||
buttonText | ||
buttonUrl | ||
} | ||
} | ||
... on libraryAlert_GlobalSet { | ||
title: entryTitle | ||
text: richTextAlertBox | ||
} | ||
} | ||
} | ||
` | ||
export default cachedEventHandler(async () => { | ||
const keys = await useStorage().getKeys() | ||
const endpoint = useRuntimeConfig().public.craftGraphqlURL | ||
|
||
// const keys = await useStorage().getKeys() | ||
// console.log('Server api storage keys:' + JSON.stringify(keys)) | ||
const globalData = await useStorage().getItem('craftData:globals') | ||
let globalData = await useStorage().getItem('craftData:globals') | ||
console.log('Server api Global Data object:' + JSON.stringify(globalData)) | ||
if (!globalData) { | ||
const { data } = await $fetch(endpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ query: globalsQuery }) | ||
}) | ||
await useStorage().setItem('craftData:globals', data) | ||
globalData = await useStorage().getItem('craftData:globals') | ||
console.log('Server api Global Data object first set and then get:' + JSON.stringify(globalData)) | ||
} | ||
return globalData | ||
}) |
Oops, something went wrong.