A headless CMS is a content management system that separates the content from the presentation layer. The content is stored in a central location, but can be accessed and displayed on any device or platform. This is in contrast to a traditional CMS, which combines the content and presentation layers into a single system. Because of this separation, a headless CMS offers more flexibility in where and how you present content e.g. you can choose any front-end framework or technology. If this interests you, read on - I’ll walk through the deployment of an open-source headless CMS, Strapi, on Railway.
What is Strapi CMS?
Strapi is an open-source, fast and secure headless CMS that enables developers to create and manage content programmatically. It is built on top of Node.js and designed to be front-end agnostic. It provides an intuitive administration panel to create and manage different content types like articles, images, videos etc. Developers can also query content using standard RESTful APIs or GraphQL. Strapi has several security features, including reusable policies, CORS, CSP, P3P, Xframe, XSS, and more. Strapi works with PostgreSQL, MySQL, MariaDB, and SQLite databases, and can be self-hosted or managed using Strapi Cloud.
What is Railway?
Railway is a modern app hosting platform that makes it easy to deploy production-ready apps quickly. Railway offers persistent database services for PostgreSQL, MySQL, MongoDB, and Redis, as well as application services with a GitHub repository as the deployment source. For the latter, Railway can automatically determine the application runtime and deploy the service. Railway offers several one-click starters for popular applications, including Strapi CMS. Since we are just testing the waters, Railway's free tier should be sufficient to host the service.
Deploy Strapi using One-Click Starter on Railway
Sign up for an account with Railway using GitHub, and click
Authorize Railway App when redirected. Review and agree to Railway's Terms of Service and Fair Use Policy if prompted. Launch the Strapi one-click starter template (or click the button below) to deploy Strapi instantly on Railway.
You'll be given an opportunity to change the default repository name and set it private, if you'd like. Fill in the environment variables listed below, and click
Deploy; the deployment will kick off immediately.
ADMIN_JWT_SECRET: Secret used to encode JWTs
JWT_SECRET: Random string used to generate new JWTs
APP_KEYS: Session keys used by session middleware
API_TOKEN_SALT: Hash salt used to generate API tokens
CLOUDINARY_NAME(optional): Required if you want images to be persisted.
CLOUDINARY_KEY(optional): Required if you want images to be persisted.
CLOUDINARY_SECRET(optional): Required if you want images to be persisted.
Once the deployment completes, a Strapi instance will be available at a default
xxx.up.railway.app domain - launch this URL to access the app. If you are interested in setting up a custom domain, I covered it at length in a previous post - see the final section here.
xxx.up.railway.app\admin to access the Strapi administration portal, and create the first admin user. Provide the details and click
Getting Started with Strapi CMS
Once you log in, you'll see the default Strapi dashboard. The Railway template sets up Strapi with a SQLite database; see this guide for other options.
Before we get into the content management, let's have a look at the configuration options and other sections. The
Settings page allows you to manage API tokens, configure webhooks, define role-based access control, configure email, and more.
Media Library lets you upload your assets manually, and also displays assets that are uploaded programmatically.
Plugins are modular extensions that add specific functionality to Strapi e.g. the GraphQL plugin adds support for the GraphQL query language. Several plugins are installed by default, and more can be installed from the marketplace.
Now, let's look at content management in Strapi. The official Quick Start Guide is quite good, and covers the detailed steps required to create new collections, use the collection types to create new entries, publish the content, and use the API to query the Strapi CMS. There is no added value in duplicating the steps here, so I'll just highlight the key points instead.
Content-Type Builder to create new collection types, and manage existing ones. You can also define one-to-many, many-to-many relationships between the content types.
Once you have the basic data structures in place, create entries for the content types. These are meant to pre-populate the CMS and help with initial rendering of your frontend code, but the entries can be added later/programmatically too.
Now that you know the basics of deploying a self-hosted Strapi CMS instance and publishing content with Strapi, go ahead and explore the Quick Start Guide for step-by-step guidance on headless content management.