These are chat archives for locomotivecms/v3

9th
Mar 2017
Dan de Havilland
@dandehavilland
Mar 09 15:02
I'd also really like to know the answer to @tomaswitek 's question. This has just come up in a project and the only solution so far seems to be a small backend app to proxy requests to the API.
Didier Lafforgue
@did
Mar 09 15:02
hi @tomaswitek and @dandehavilland!
you can absolutely use Locomotive as a headless CMS
local.ch (Swiss Yellow Pages) is using Locomotive for small sites AND also as a headless CMS to populate list of items
they don’t use the Locomotive Restful API
:-)
how do they do it?
they created JSON liquid pages :-)
Dan de Havilland
@dandehavilland
Mar 09 15:04
Ah, very interesting.
I'll read up on that :) Thanks!
Didier Lafforgue
@did
Mar 09 15:05
the biggest benefit of having JSON liquid pages over the default Restful API is that you’ve got total control over your JSON response
hi @jprof7, thanks for the tip!
Dan de Havilland
@dandehavilland
Mar 09 15:15
@did is there a way to set CORS headers on locomotive?
Didier Lafforgue
@did
Mar 09 15:15
for your JSON responses?
Dan de Havilland
@dandehavilland
Mar 09 15:16
Yes
Didier Lafforgue
@did
Mar 09 15:16
yes
Liquid pages are rendered by the Locomotive Steam component which is basically a rack app.
Dan de Havilland
@dandehavilland
Mar 09 15:17
We're using a hosted 'engine'.
Is it still possible?
Didier Lafforgue
@did
Mar 09 15:17
locomotive v3 or v2?
Dan de Havilland
@dandehavilland
Mar 09 15:17
v3
Didier Lafforgue
@did
Mar 09 15:18
what is the rack middleware you’re going to add to handle CORS headers?
Dan de Havilland
@dandehavilland
Mar 09 15:20
To be clear, our CMS is hosted on locomotivecms.com and we're trying to pull the data into our JS frontend. Are we able to use our own rack middleware on this hosted CMS?
Tomáš Witek
@tomaswitek
Mar 09 15:21
@did OK thx for the answer, so they are doing something like this? https://gist.github.com/LukeWinikates/4416936
Dan de Havilland
@dandehavilland
Mar 09 15:21
JS frontend is hosted on another domain
Didier Lafforgue
@did
Mar 09 15:22
@dandehavilland, oh okay, I didn’t get that :-) what are the headers (+ values) you need to return?
@tomaswitek yes, you can use the liquid json filter to avoid double quotes
”url”: {{ post.url | json }}
Tomáš Witek
@tomaswitek
Mar 09 15:24
@did is local.ch using locomotive as it's main backend/editor system?
Dan de Havilland
@dandehavilland
Mar 09 15:24
We'd just need to allow access from our frontend: Access-Control-Allow-Origin: http://www.mydomain.com
Am I mistaken, or does it already allow *?
Didier Lafforgue
@did
Mar 09 15:25
@tomaswitek you’re from Zurich! I’ve not noticed it! yeah, they use Locomotive for some blogs and small sites.
Dan de Havilland
@dandehavilland
Mar 09 15:25
(I didn't check until now)
Tomáš Witek
@tomaswitek
Mar 09 15:26
@did yep I live in Zurich that's why I am asking :D
Didier Lafforgue
@did
Mar 09 15:27
@dandehavilland hmm, could it be defined on the site level? I’m asking you that because I could define a site property for that purpose.
Dan de Havilland
@dandehavilland
Mar 09 15:28
Thanks @did - I'll get back to you about that. We're still scoping this part out at the moment and it may already do what we need afterall.
Didier Lafforgue
@did
Mar 09 15:29
@dandehavilland you’re welcome!
Tomáš Witek
@tomaswitek
Mar 09 15:29
Thx @did as well, you're doing a great work here ;)
Didier Lafforgue
@did
Mar 09 15:29
thanks ;-)
Dan de Havilland
@dandehavilland
Mar 09 16:08
@did another question if you're still around: we're rendering JSON but some UTF characters are not being encoded correctly in the output. Can we specify the charset/content type for a specific page?
Didier Lafforgue
@did
Mar 09 16:08
does it happen in Wagon as well?
Dan de Havilland
@dandehavilland
Mar 09 16:09
Yes, we're seeing it locally in wagon.
Didier Lafforgue
@did
Mar 09 16:10
hmmm
<content type>; charset=utf-8 should be the value
used for the Content-Type header
Dan de Havilland
@dandehavilland
Mar 09 16:11
Can we specify this in the template?
Didier Lafforgue
@did
Mar 09 16:11
open an issue in the Steam GH repo, I will fix it ASAP
(no)
Dan de Havilland
@dandehavilland
Mar 09 16:12
OK, will do. Thanks
Didier Lafforgue
@did
Mar 09 16:12
hmm
hold on
@dandehavilland
in the YAML header of your page, add this:
response_type: application/json; charset=utf-8
Dan de Havilland
@dandehavilland
Mar 09 16:15
Unfortunately we tried that, but to no avail.
It appears correctly in our data yaml as "ê", but is badly encoded in the output
Didier Lafforgue
@did
Mar 09 16:15
are you sure you saved your data yaml file in utf-8?
Dan de Havilland
@dandehavilland
Mar 09 16:16
The data yaml was created on the engine and sync'd to the local machine using wagon sync.
I'll check the encoding, just a sec.
Yes, it's definitely a UTF8 file
Didier Lafforgue
@did
Mar 09 16:19
okay….
Dan de Havilland
@dandehavilland
Mar 09 16:21
We've also tried adding other accented characters to the file and they are also badly encoded on output. We're going to try on the engine.
Didier Lafforgue
@did
Mar 09 16:21
that’s really weird, I’ve got sites in French (so with accents) and they are displayed perfectly
Dan de Havilland
@dandehavilland
Mar 09 16:39
After further investigation, it appears to be a browser issue. We were previewing the JSON in Safari...
curling gives us the correct encoding.
Thanks for your help anyway @did!
Didier Lafforgue
@did
Mar 09 16:40
okay . thanks for the update :-)