After realizing several projects with Kirby and loving the CMS I would like to go a further step and explore the realm of Kirby as a headless CMS.
I tried to setup kirby-headless-starter by Johann Schopplich and his NuxtKQL plugin.
I followed the guide in the starter kit as well as the NuxtKQL (both links above).
- Cloned the repo
- ran
composer install
to install the CMS - Setup the .env at the root of the project
- init a nuxt 3 project with the name
/frontend
- init nuxtKQL module for nuxt
- created another .env in the
/frontend
folder - Adjusted the
nuxt.config.ts
Now I run my kirby instance with laravel valet. When i test a query using insomnia to: https://nuxt-kirby-gpt.test/api/kql
i get a response as expected:
{
"code": 200,
"status": "OK",
"result": {
"children": [
"photography",
"notes",
"about",
"error",
"home",
"sandbox"
],
"drafts": [],
"files": [],
"title": "Mægazine",
"url": "https:\/\/nuxt-kirby-gpt.test"
}
}
So i guess the problem does not lay in the kirby setup.
But when i try to fetch some example data into my nuxt frontend with this snippet from the NuxtKQL guide:
<script setup lang="ts">
const { data, pending, refresh, error } = await useKql({
query: 'site',
select: {
title: true,
children: true
}
})
</script>
<template>
<div>
<h1>{{ data?.result?.title }}</h1>
<pre>{{ JSON.stringify(data?.result, undefined, 2) }}</pre>
</div>
</template>
I get the following error:
Error: [POST] "/api/__kirby__/KEY": 503 Service Unavailable
I quadruple checked both the .env files to make sure the url and token are correct but still here they are:
.env
:
KIRBY_DEBUG=true
KIRBY_PANEL_INSTALL=true
KIRBY_CACHE=false
KIRBY_HEADLESS_API_TOKEN=my_token
KIRBY_HEADLESS_FRONTEND_URL=http://localhost:3000
KIRBY_HEADLESS_ALLOW_ORIGIN=*
/frontend/.env
:
KIRBY_BASE_URL=https://nuxt-kirby-gpt.test
KIRBY_API_TOKEN=my_token
I went though the whole setup three times. The same error always occured. I hope somebody might know already what could be the issue. I am happy to provide more information if needed.