# Kirby 3 as Headless CMS for Vue/Nuxt

**URL:** <https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 15, 2019, 3:50pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142 "2019-01-15T15:50:55Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 7:52am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/41 "2019-01-24T07:52:22Z")

</div>

> [@mattlenz](#):
>
> I’ve got a basic kirbytext to HTML parser that would be helpful but it needs some work.

@mattlenz I have been putting things in place for the same, you sound further ahead, want to work together on this?

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:00am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/42 "2019-01-24T09:00:51Z")

</div>

Without having read all the replies, heres a website using Kirby 3 as headless CMS with a Nuxt.js Frontend:

> **[robinscholz/CYMB\_Backend](https://github.com/robinscholz/CYMB_Backend)**
>
> Backend for photographer Constantin Mirbach. Contribute to robinscholz/CYMB\_Backend development by creating an account on GitHub.

  

> **[robinscholz/CYMB\_Frontend](https://github.com/robinscholz/CYMB_Frontend)**
>
> Frontend for photographer Constantin Mirbach. Contribute to robinscholz/CYMB\_Frontend development by creating an account on GitHub.

It’s definitely takes a bit of effort to setup, but works great!

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:05am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/43 "2019-01-24T09:05:47Z")

</div>

Do you serve your local server with a https certificate?

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:11am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/44 "2019-01-24T09:11:17Z")

</div>

Somewhat solved this with a custom endpoint: [https://github.com/robinscholz/CYMB\_Backend/blob/master/site/config/config.php](https://github.com/robinscholz/CYMB_Backend/blob/master/site/config/config.php)

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 9:14am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/45 "2019-01-24T09:14:23Z")

</div>

I am looking through the code, but cant see if you are. How you handle kirbytext?

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:26am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/46 "2019-01-24T09:26:11Z")

</div>

The custom endpoint converts kirbytags:

```auto
function kt($array) {
  foreach ($array as $key => $value) {
    if (is_array($value)) {
      $array[$key] = kt($value);
    } else {
      $array[$key] = kirbytags($value);
    }
 }
  return $array;
}

```

You could probably do the same for kirbytext, though with some more sophisticated code.  
Somehow you’d need to figure out which fields to convert and which to leave untouched. Otherwise every field might get wrapped in `<p>` tags.

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 9:28am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/47 "2019-01-24T09:28:02Z")

</div>

That would mean sending HTML over the API response?

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:29am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/48 "2019-01-24T09:29:00Z")

</div>

Sure, if you parse it server side, you will have to.

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 9:30am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/49 "2019-01-24T09:30:40Z")

</div>

Thats a big red line for me, I started putting together client side Kirbytext parse, sounds like @mattlenz has made better progress than me.

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:31am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/50 "2019-01-24T09:31:25Z")

</div>

Could you explain why? Not sure what’s the downside here.

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 9:36am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/51 "2019-01-24T09:36:26Z")

</div>

While it will make the implementation simpler, anything that renders raw html received from external source is not great practice from a security point of view. The source could be ‘spoofed’. While parsing the kirbytext does not fully mitigate this, its controlled and only the relevant tags are parsed.

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [January 24, 2019, 9:38am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/52 "2019-01-24T09:38:53Z")

</div>

Fair enough, but I would argue that for alot of kirby based projects this risk could be considered acceptable. Nevertheless I’d definitely welcome a client side Kirbytext parser!

---

<div class="post-metadata">

**Author:** ![afincato](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/afincato/32/3446_2.png) [@afincato](https://forum.getkirby.com/u/afincato)\
**Post date:** [January 24, 2019, 10:47am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/53 "2019-01-24T10:47:14Z")

</div>

really enjoying the evolution of the conversation!

re: parsing text. for now i’ve just been using markdown instead of kirbytext. this can’t work for all projects of course, but unless you use specific plugins in the panel that introduce their own tags, it’s fine.

definitely up to help out if needed on the kirbytext client side parser 🙂

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 1:58pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/54 "2019-01-24T13:58:13Z")

</div>

Just spent the last 10 mins writing a regex for the kirbytext tags

`([a-z]*):\s[a-z\s]*(?![a-z]*:)`

> **[Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript](https://regex101.com/r/sZZN5u/2)**
>
> Regex101 allows you to create, debug, test and have your expressions explained for PHP, PCRE, Python, Golang and JavaScript. The website also features a community where you can share useful expressions.

This is what I have so far … anyone wanna have a go improving? I have listed 2 known issues with it. My parser already extracts the tags them selves, so its just the content parsing required, once these 2 are nailed that basis is done.

Edit, Yes I know it only works with lower case etc, its easier to debug this way.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [January 24, 2019, 2:23pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/55 "2019-01-24T14:23:45Z")

</div>

I think I wrote this on Slack already, but maybe you have missed it: Kirby also uses RegEx for parsing, so why don’t you use [ours](https://github.com/getkirby/kirby/tree/master/src/Text)?

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 24, 2019, 2:29pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/56 "2019-01-24T14:29:01Z")

</div>

Ah wasn’t sure who and where messaged me that, I will look at it now.

---

<div class="post-metadata">

**Author:** ![mattlenz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mattlenz/32/6048_2.png) [@mattlenz](https://forum.getkirby.com/u/mattlenz)\
**Post date:** [January 24, 2019, 8:11pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/57 "2019-01-24T20:11:02Z")

</div>

Handling kirbytext on the server-side as @rbnschlz has shown would be much simpler than to rewrite kirbytext in js.

Doing it on the client/js side means you lose all internal kirby context. You have to manually re-implement every tag and lose any custom tags you’ve written. Plus creating proper image tags requires looking up the image file from the page object to retrieve the URL.

@DanielRivers here’s where I got to (warning; messy) if you want to pick up where I left off [https://gist.github.com/mattlenz/78154ed23c9318df587126dc7fed1293](https://gist.github.com/mattlenz/78154ed23c9318df587126dc7fed1293)

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 25, 2019, 9:13am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/58 "2019-01-25T09:13:33Z")

</div>

I totally understand the hurdles, but I feel that they are all solvable.

1. tag -\> HTML I don’t believe is a massive challenge, with the handful of ‘official’ tags its not awful.
2. With this approach, custom tags would be written solely in JS and not extended in Kirby
3. Context aware image is solvable using windows.location.

I will fork your gist and make some changes I had in mind.

---

<div class="post-metadata">

**Author:** ![bornToBeRoot](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/borntoberoot/32/12482_2.png) [@bornToBeRoot](https://forum.getkirby.com/u/bornToBeRoot)\
**Post date:** [January 28, 2019, 12:38pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/59 "2019-01-28T12:38:06Z")

</div>

I got the API to work with both types of authentification. But as far as I understand and tested the API can not be used as a backend for **public websites** so far. This is why authentification is always required and defining a “Guest-User” with no access to the panel doesn’t help.

Another drawback is – correct me if I’m wrong - that kirbytext-fields can not be delivered as parsed HTML. That would mean that the frontend would have to do that which is unnecessary overhead.

(Another point that would be nice is if the API would deliver blueprint’s field-information along with the data. I didn’t find any option for that.)

---

<div class="post-metadata">

**Author:** ![DanielRivers](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/danielrivers/32/176_2.png) [@DanielRivers](https://forum.getkirby.com/u/DanielRivers)\
**Post date:** [January 28, 2019, 12:41pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/60 "2019-01-28T12:41:38Z")

</div>

> [@bornToBeRoot](#):
>
> That would mean that the frontend would have to do that which is unnecessary overhead.

TBH, that’s necessary overhead in my case. Delivering HTML from external source and rendering straight into your page is really bad practice. Though mentioned above, many of sites that run kirby, this may not be a concern for some. I am working on a client side parser, though been distracted with my K2-\>k3 conversion

[Previous page](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142.md?page=2)

[Next page](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142.md?page=4)
