» FrontAid CMS / Help

How to use FrontAid CMS without connecting it to my Git project?

FrontAid is a very flexible CMS. It allows you to create arbitrary data models and stores your content directly in your own Git repository. Usually, the content and source code are thus side by side each other. Sometimes there are use cases where that is not desired or not possible, though. Maybe your project is not hosted on a Git provider that is supported by FrontAid CMS. Or there might be a company policy that disallows using third-party Git applications. Or maybe your company does not even use Git at all. Or you might share the same content among different repositories.

So there are definitely use cases where FrontAid CMS cannot be directly connected to your projects. But there are ways to integrate it nonetheless. This post will show you how.

Set up a Git Repository for the Content

Using a Git repository (e.g. GitHub) that is supported by FrontAid CMS, is still necessary. But you can use it to exclusively store the Model and Content files without anything else. After that has been set up, we will show how you can connect it to your actual project repository that may be hosted somewhere else.

To start, either use an existing GitHub account or create one exclusively for FrontAid CMS. Then do the same with a repository that you will use. When that is done, follow the instructions of Setup & Git Integration to connect and configure FrontAid CMS. After those steps, you now have a Git repository that stores Content and Model files. And now we are connecting that to your actual repository.

Retrieve updated Content

The following setup will show how to connect to the Git repository that stores the Content, download it and store it in your actual project. That step will be automated by a command line script so that it is easy to repeat. Essentially, we have to download a single file from a public or private Git repository (e.g. from GitHub). Using a public one is slightly easier as a private repository requires an additional one-time setup.

Use a public Repository

A public repository can be read by anyone. If you store your Model and Content files in a public repository on GitHub, you can simply use a download URL like the following. Make sure to replace the user-name/repository-name with your actual names and content-file with the path and name of the Content file. If you use a different branch than the “master” branch, you have to update that accordingly. Now that you created a Content file download URL, make sure it works.

Download URL: https://raw.githubusercontent.com/<user-name>/<repository-name>/master/<content-file>.json

Use a private Repository

A private repository can only be read by accounts that have the corresponding permissions. So to download a file by URL, you have to get a token that authenticates your account. For GitHub, such a URL will look like the one below. Go through Creating a personal access token and make sure to grant the “repo” permission. Then copy the token and replace access-token with it. Also make sure to replace user-name, repository-name, and content-file accordingly. If you are using a branch different from “master”, also replace that. Now that you created a Content file download URL, make sure it works. If you get “404: Not Found” please be aware that either the file path might be wrong or the token is not set up correctly.

Download URL: https://<access-token>@raw.githubusercontent.com/<user-name>/<repository-name>/master/<content-file>.json

Download the Content

Now that you have a URL to download the Content file from the repository, the next step is to actually automate that. For example, you can include it in your build tool chain to always use the latest content. We will use the command line tool curl to download and store the file. Find an example below. This script will request the given URL, download the response, and thanks to the -O option store it on your local file system. Now to actually download a real Content file, replace the URL with the download URL you got from the steps above. You can run this script however you like. Developers often use tool runners to make that step easier. Often used examples of such tool runners are Make and npm.

curl -O https://example.com

For Make, create a new “Makefile” or update the existing one and add the command below. Make sure that you add a tab, and not one or multiple spaces, before the second line. And also replace the example URL with the actual download URL. Now you can run it by executing make content.

content:
    curl -O https://example.com

With npm scripts, you can similarly simplify that. Create or update your package.json file by adding the content script to the scripts section. And don’t forget to use the real download URL instead of example.com. Afterwards you can run it by executing npm run content.

{
  "scripts": {
    "content": "curl -O https://example.com"
  }
}

Now whenever you run the script that you just set up, it will download and store the Content that is managed with FrontAid CMS. That way you can use FrontAid with your project but have the two completely separated from each other. Be it because of security policies or multiple different projects that use the same Content. FrontAid CMS is highly flexible and this headless Content Management can come in handy for various projects.

Optional: Use Git Hooks

You can even further automate the Content update step by using Git Hooks. Those Hooks run every time a certain action is being performed using Git. For example, you can automatically update the Content file every time you perform git pull. To do that, open the directory “.git/hooks” and verify whether you have a file called post-merge in there. If you don’t, you have to create it and make it executable.

touch .git/hooks/post-merge
chmod +x .git/hooks/post-merge

And then add the script below to the “post-merge” file (make sure to update the URL appropriately). The post-merge hook will be executed every time that a merge occurs, and that includes Git pull. So when you perform Git pull, the hook will be executed and the Content file will thus be updated.

#!/bin/sh
curl -O https://example.com