johannschopplich / kirby-headless-starter

🦭 Headless-first Kirby starter with bearer token authentication and KQL utilities
https://kirby.tools/docs/headless
MIT License
64 stars 4 forks source link

Unable to fetch site data through __site__.php template #6

Closed nejdl closed 6 months ago

nejdl commented 6 months ago

Thanks for providing such a nice Kirby headless starter, I’m currently trying it out with NextJS! I’m using the default php templates to output JSON, which I then fetch (with bearer token authentication) from my frontend. This works great with your Kirby headless setup!

The only thing I’m having trouble with is fetching the site data from the __site__.php template. When I try to fetch /__site__ I get the error that this page cannot be found.

If I remember correctly, I have successfully fetched the site data before (with your kirby-headless plugin v.1.3 and Kirby 3) by fetching the _site.php template from /_site. Has anything changed with the way that I need to fetch the site data (apart from fetching /__site__ instead of /_site now)?

I can find a workaround by fetching the site data through another page or using the API differently, so no worries – just wondering if I am missing something simple!

johannschopplich commented 6 months ago

Hi there!

Yes, the path has changed with Kirby Headless v3. You have to fetch the site data from /api/__site__, just like (for example) /api/__sitemap__ and authenticate with a bearer token. The site data is now hidden under the API.

For reference, you can always check out my Cacao Kit frontend, which should give you ideas how to implement a headless Kirby integration with Next.js based on the work done for Nuxt. 🙂

nejdl commented 6 months ago

Perfect, I‘ll do it that way and will check out the Cacao kit! Thank you for your help! 🙂