Server

Contentful Wasting your Time? Try Cockpit

So I tried to get up and running with Contentful recently, and oh what a nightmare. Created my space, the content type. The content model and content. Now time to consume? Well not quite. Couldn’t consume the way I wanted. Switched to Cockpit, and was up and running in less than 15 minutes. Here’s how to get up and running with Cockpit seamlessly.

After a month with Contentful

My problem with Contentful was simple. I’ve created many entries to a content type. I want to retrieve all the entries of the content type.

Is this supposed to be what does the job?

getEntries(entry_id?) {
  return Observable.fromPromise(this.cdaClient.getEntries(entry_id))
    .map((res) => {
       return res.items;
     });
}

the cdaClient is imported from

import { createClient, Entry } from 'contentful';

From the docs, at least that’s how I understood it, except the above was retrieving every single content of a space for me. I’m probably doing something wrong, however, that’s as a result of how ambiguous their documentation is.

Or perhaps, I might be the dumb guy. Whatever the case, dumb guys use dumb tools, right?

I tried wrapping my head around Contentful within about a month timeframe. I would come back again and again to Contentful, re-read the docs, to see if I wasn’t missing anything.

Nothing fruitful.

Let’s see how Cockpit fit right into my needs and made my life easier.

My Needs

In building PackageToMe, I wanted a simple, really simple CMS, sitting outside the application, which I could even use for static parts of the site, like the TOC, About and Safety pages.

PackageToMe uses the MEAN stack, thus storing such content in MongoDB is possible. However, I wanted something seamless, not sitting with the actual application, that I could go in swiftly to make changes to static content as and when needed, without having to rebuild the frontend part, or spin up collections in MongoDB which would come with its related authentication etc.

In addition, I wanted a central API CMS I could use for other sites of mine, and not necessarily tied to a specific website.

And oh, had support for Markdown too.

Setting up Cockpit

server {
    listen 443 ssl http2;

    root /var/www/cockpit;
    index index.php;

    server_name cockpit.example.co;

    include /etc/nginx/ssl/ssl-params.conf;
    include /etc/nginx/ssl/khophi.ssl;

    error_log /var/log/nginx/cockpit_error.log;
    access_log /var/log/nginx/cockpit_access.log;
    
    include /etc/nginx/snippets/wordpress.conf;
   
    include /etc/nginx/snippets/statics.conf;
}

server {
    listen 80;
    server_name cockpit.example.co;
    return 301 https://$server_name$request_uri;
}

The above can be your nginx conf for proxying Cockpit.

And your /etc/nginx/snippets/wordpress.conf could look like this:

location / {
    # no php is touched for static content
    gzip_static on;
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ .sqlite$ { deny all; }

location ~ \.php$ {
    fastcgi_hide_header X-Powered-By;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
}

Why is it called wordpress.conf? Well because it’s the same configuration file I’m using for the WordPress setups that are being used for the Cockpit. Really?

Yeah, Cockpit is PHP, for the most part.

Then download Cockpit, extract and relocate folder to somewhere of your choice.

  • Download: wget https://github.com/agentejo/cockpit/archive/master.zip
  • Extract: unzip cockpit-master
  • Copy: cp cockpit-master/* /var/www/cockpit (assuming /var/www/cockpit already exists)
  • Then make sure that the storage folder , and all of its subfolders have write-access permission.

If all checks out, reload nginx service nginx reload and point to cockpit.example.co/installto install and then off your go.

Here’s mine in action after installation:

Lemme know how your setup goes in the comments below, and have fun.

Contentful is overkill for what it’s probably intended to do. Too many moving parts. If you need something basic but functional, Cockpit might be for you, just like it is for me.

See you in the next one.

Related Articles

Back to top button