Hi.
I am using Strapi for API now and wondering if I could use it as well for a front end, meaning generate html and return a response with proper headers so it renders in the browser. By doing this I’ll catch both rabbits: have an api and an HTML engine for the front end website.
Right now domain.com will fail, domain.com/api will be the rest api endpoint, and domain.com/dashboard will be the content manager ui.
Is it possible to create a certain route (?) so I handle all browser requests and prep HTML templates response? Kind of write my own routing/templating for HTML…that operates under domain.com?
Otherwise I run two apps, Strapi, as well as express.js which makes (internal network) rest calls to Strapi to pull data, then generate HTML, then sends it back to the browser. Unnecessary extra hops and latency.
Thanks for reading this.
1 Like
Hi @ahalilov,
While it might be technically possible (you can create controllers that output HTML over JSON) , I don’t think that you should want that. If you want your data to be intertwined with your HTML – like you’d have to do with PHP for instance – there are better CMS systems out there. Are you familiar with javascript frameworks as React, Vue, Angular, Svelte or other modern frameworks? These all create a static HTML+CSS+JS project, and get their data from API endpoints.
If you don’t want to use javascript for instance on your front-end, it could be possible to generate HTML pages with data from the CMS. But I don’t think that it should be integrated within Strapi.
Hi,
Thank you for your response. I wanted to avoid building a React app as I have a fairly simple website, and I want it to be pure SSR.
1 Like
Well, I would suggest to create a separate node project that requests an /api/pages
endpoint to retrieve all of the pages, and generate HTML pages base on their values.
No… that would still sound over complicating it to me. I am using VUE myself for my front-end and I use Vite-SSG for generating HTML pages from my routes (here they do it with nextJS). Motivation for this is because I want to have control over styling, and it would be a pain in the ass to do this in a pure Strapi solution. If you just want basic, static HTML, why don’t you consider a tool like jekyll?
1 Like
I was just browsing the marketplace, maybe this plug-in suits your needs?
Thanks, everyone. I would probably build a website (front-end) separately and connect it via API to Strapi to fetch data. Everything else will make future upgrades complicated.