TNS
VOXPOP
Favorite Social Media Timesink
When you take a break from work, where are you going?
Instagram/Facebook
0%
Discord/Slack
0%
LinkedIn
0%
Video clips on TikTok/YouTube
0%
X, Bluesky, Mastodon et al...
0%
Web surfing
0%
I do not get distracted by petty amusements
0%
Serverless / Software Development

How to Build a Serverless, SEO-Friendly React Blog

May 1st, 2017 12:00pm by
Featued image for: How to Build a Serverless, SEO-Friendly React Blog

Roger Jin
Roger Jin is a developer and technical writer at ButterCMS where he focuses on tools to make developers’ lives easier. Mixing his passion of programming and education, he writes articles focusing on serverless development, microservices, and much more. He develops mostly with React, Node.js, Elixir, and Ruby.

Serverless application architectures are gaining in popularity and it’s no mystery why. Developers are able to build and iterate on products faster when they have less infrastructure to maintain and don’t need to worry about server maintenance, outages, and scaling bottlenecks.

In this tutorial, we are going to show you how to build a serverless, CMS-powered blog using React, ButterCMS, and built-in prerendering through Netlify. The finished code for this tutorial is available on Github.

ButterCMS is a hosted API-based CMS and content API that lets you build CMS-powered apps using any programming language including Ruby, Rails, Node.js, .NET, Python, Phoenix, Django, Flask, React, Angular, Go, PHP, Laravel, Elixir, and Meteor. Butter lets you manage content using a hosted dashboard and integrate it into your front-end of choice with our API — you can think of Butter as similar to WordPress except that you build your website in your language of choice and then plug-in the dynamic content using an API.

Netlify is a static website hosting service that streamlines integration with prerendering services like Prerender.io, SEO.js, and Brombone.

Getting Started

We’ll use the Create React App starter kit.

Install Create React App:


Then create the boilerplate for our app:

Adding Routing

Our blog needs two pages: one for listing all posts and another for displaying individual posts. Create BlogHome.jsand BlogPost.js components in the src directory:



Create React App doesn’t offer routing out-of-the-box so we’ll add react-router:


In the source folder, create a new file called routes.js. We’ll create routes for the blog home page with and without page parameters, as well as the individual post page:

Next, we’ll update index.js so it uses our routes when initializing the application:

And finally, we’ll update App.js so it nests child components specified in our routes:

Building the Blog

We’ll use ButterCMS to build our blog. ButterCMS provides content APIs for blog posts, categories, tags, and authors.

First, we’ll install the ButterCMS Node.js API client:


We’ll then update ‘BlogHome’ to fetch posts from ButterCMS and render them. Use the API token in the example below or get your own by signing into ButterCMS with Github.