Serving static files with Ghost

Julien Tanguy, . Tagged

You probably know that this blog is powered by Ghost and can be hosted on Clever Cloud in a couple of minutes. If not, you can read the first article of this blog for more context for this article.

Verifing a website on keybase

I just moved to https://jtanguy.cleverapps.io as my main website, and I wanted to add this site as a proof on keybase.

There are two ways to verify a website on keybase:

  1. Add a txt entry on the DNS record, and
  2. Host a keybase.txt file on the server.

The first option is not possible for me, since cleverapps.io is a domain owned by Clever Cloud, not by me. I had to take option 2.

I found out that Ghost does not offer an easy solution to host static files outside of it’s theme.

However, there is a trick for that: ghost itself is an express app Actually, it’s several express applications: the blog, the api, and the admin interface., and can be wrapped in another express app.

For this, add your keybase.txt somewhere in the clevercloud-ghost packaged ghost, and replace the index.js with the following:

const path = require('path');
const ghost = require('ghost');
const express = require('express');

const wrapperApp = express();

  config: path.join(__dirname, 'config.js')
}).then(function (ghostServer) {
    wrapperApp.get('/keybase.txt', function(req, res, next) {
        res.sendFile(path.join(__dirname, 'path', 'to', 'your', 'keybase.txt'));
    wrapperApp.use(ghostServer.config.paths.subdir, ghostServer.rootApp);


Push your code and a few minutes later, voilĂ .

One improvement could be to use make a proxy app to query directly the files on cellar Cellar an S3-like storage solution hosted by Clever Cloud, and is used to serve the images on this blog., without needing to commit the keybase file in the repository.

That’s all folks !