2

I really love working with Craft, especially around how easy and user friendly it is. However, I do work with React/Vue and usually I setup a node server/app that will do some routing, render views and so on...

Would it be a good idea to have a setup like this:

  • Frontend: React / Vue
  • Backend: node app that has all my public routes setup, rendering views, server side render React/Vue etc
  • Backend no 2: Craft CMS with Element API setup

Example:

  • User requests /contact/person-1
  • The request will be matched in my node app as a valid route
  • Node app will make request to the API that has been setup for Craft, fetches the relevant info about Person 1, returns the result to node
  • Node app renders the view with the data that was fetched

Is this O.K. or completely nuts? Will it be ineffective or is it a good way to structure it like this when I'm in need for a nice CMS like Craft... ?

Please help me out on finding the best approach!

2
  • @nicklman I like to know what is the conclusion of this? did you able to work with React, Node Craft and EAPI? May 15 '20 at 15:51
  • 1
    Yes. I did it like I describe in my list. In order to get SSR to work, and do the necessary requests before view is rendered I used frontload-connect in my React setup. But if a user navigates to another route after the first route he/she entered, the api request will happen on frontend only, but thats more of how React Router works = it renders the requested route right away. In those cases I just put up a spinner while fetching api data. Does that answer some of your questions?
    – nickelman
    May 15 '20 at 16:11
1

So you can definitely do this... the article Using VueJS + GraphQL to make Practical Magic has a detailed explanation of how to accomplish this using the CraftQL plugin and GraphQL... which I think you may find much nicer to work with than custom Element API endpoint(s).

However you can definitely do it with an Element API endpoint as well. It's just a bit more work, and a bit more in PHP-land.

0
1

Sounds like you're using craft in 'headless' mode. I've heard about that for drupal, but not for craft. I don't see any reason why it wouldn't work. You get the craft UX for creating and modifying entities, but use node as a proxy and view generator.

1
  • Yes, exactly, looks like it could be a nice way to go then. Cheers
    – nickelman
    Oct 10 '18 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.