Back to blog
Headless CMS 6 min read 0 views

How to Add a Blog to a Replit App Without Hard-Coding Content

Stop pasting blog posts into components. Keep your Replit app for the code, move posts into a CMS, fetch them on the server with your key in Replit Secrets, and let an AI draft posts a person publishes.

Aditya Kadam Garchi CMS

Replit Agent gets an app running fast. Ask it for a blog and it may do the quickest thing: put your first article inside a component or a route file as a block of text. On launch day it looks finished.

A week later you want a second post. Then you spot a typo in the first. Then a colleague who has never opened Replit wants to write something. Each of those now means prompting the agent, checking what it changed and redeploying. Your blog runs on the same workflow as your payment code.

This guide moves the posts out of your code and into a CMS, while your Replit app keeps doing the rendering. The example uses Garchi CMS, which we build. The same pattern works with any headless CMS that has a server-side API.

What belongs where

Split your data by who edits it and what your app does with it.

Keep in your app and its databaseMove to the CMS
Users, logins and sessionsBlog posts and author bios
Payments and subscriptionsCategories and tags for posts
Records your app creates or acts onFAQs and changelog entries
Anything with business logic attachedSEO titles, summaries and cover images

Replit stays the place where you build and run the app. The CMS becomes the source for the words and images the blog displays.

Step 1: Create the content collection

Sign up for a free Garchi Sandbox account and create a space for your app. Add a category called Blog. In Garchi, each post is a data item: one record with a name, slug, one-line summary, rich text body and a cover image.

Write a test post by hand first. Give it a readable slug such as hello-world, a summary under 160 characters, and two extra details: author as text and published_date as a date. Use those exact keys on every post. Your code reads them by name, and one post with publish_date instead will show up with no date.

Save it as a draft for now. Avoid building twenty categories for a three-post blog. You can add more later.

Step 2: Store the API key in Replit Secrets

In the Garchi dashboard, click your profile icon, open API keys and generate a key. In Replit, add it through the Secrets tool as GARCHI_API_KEY. Add your Blog category's ID as GARCHI_BLOG_CATEGORY_ID.

Check where those secrets apply. Development and deployment can use separate configuration, so make sure the deployed app has them too.

The key must stay on the server. Don't paste it into a React component and don't expose it to the browser through a public environment variable. Anyone can read client-side code.

Step 3: Fetch posts on the server

Many Replit web apps run a Node backend such as Express. Install the Garchi Node SDK:

npm install @garchicms/garchi-node-sdk

Then add two routes that return only the fields your UI needs. A minimal Express version looks like this:

import express from "express";
import GarchiCMS from "@garchicms/garchi-node-sdk";

const app = express(); const garchi = new GarchiCMS({ api_key: process.env.GARCHI_API_KEY }); const BLOG = Number(process.env.GARCHI_BLOG_CATEGORY_ID);

app.get("/api/posts", async (req, res) => { try { const result = await garchi.compoundQuery.query( { dataset: "items", fields: ["categories"], conditions: ["eq"], values: [BLOG] }, { page: 1, size: 10, order_key: "meta.published_date", order_by: "desc" } ); res.json(result.data.map((p) => ({ slug: p.slug, title: p.name, summary: p.one_liner }))); } catch { res.status(502).json({ error: "Could not load posts" }); } });

app.get("/api/posts/:slug", async (req, res) => { try { const post = await garchi.dataItem.get({ item: req.params.slug }); if (!post?.item_id) return res.status(404).json({ error: "Not found" }); res.json(post); } catch { res.status(404).json({ error: "Not found" }); } });

Treat this as a starting point and check it against the current Node SDK docs. If your app uses another framework, the principle holds: credentials live on the server, and the browser receives content only. Any stack can also call the REST API directly.

Step 4: Build two pages

Ask Replit Agent to build the frontend on top of those routes:

Add a /blog page that lists posts from /api/posts with title and summary, each linking to /blog/:slug. Add a /blog/:slug page that loads the post from /api/posts/:slug, sanitises the HTML body before rendering it, and shows a proper not-found page when the API returns 404. Don't hardcode any post content.

Check a few details yourself. Each card should be a real link to a stable URL. Each post page needs its own title, a single H1 and alt text on images. Sanitise the body HTML whether a person or an agent wrote it.

One SEO warning. If your app is a single-page app that fetches posts in the browser after load, search engines have to run your JavaScript to see the article. Google can do that, but server rendering is the safer route for a blog you want found. If your framework supports rendering pages on the server, use it for /blog. The Next.js headless CMS SEO checklist covers the rest.

Step 5: Let an AI draft posts, and keep publishing with a person

Replit Agent built the code. For writing posts, connect any MCP-capable AI client to Garchi, such as Claude, ChatGPT, Cursor or Codex, using the server URL https://garchi.co.uk/mcp-oauth. The MCP setup page has steps for each client. Then ask:

In my Garchi space, draft a blog post in the Blog category about our new export feature. Keep it under 700 words, add author and published_date, and don't invent customer quotes or numbers.

The post lands as a draft. Garchi's API serves published items only, so it stays off your site until someone on your team reviews it and publishes it in the dashboard.

Step 6: Test the part that matters

Publish your test post and open its URL in a private window. Then change one sentence in the dashboard and publish again. Confirm the app shows the change without a new deployment. If you cache API responses, note how long the update takes.

Finally, ask someone who has never opened your Replit project to write and publish a post. If they manage it alone, your blog has become a publishing workflow instead of a demo.

Weighing other approaches first? Read how to choose a CMS for an AI-built website. Using Lovable instead? Follow the Lovable guide.

Create a free Garchi space for your Replit app

Enjoyed this article?

Get the next one in your inbox, with new Garchi features and practical ideas for running content operations with your team and AI agents. No spam, and you can unsubscribe at any time.

We only use your email to send the newsletter. Read our Privacy Policy.