Moving Blog – Again

I started to host my own WordPress blog since January 2008. First as a stand-alone installation on a cloud server, then as containers on a cloud server.

December 2017 I moved this to an AWS hosted serverless blog (see here for the source code). Technically interesting, but harder to use unfortunately.

Now I’m back on WordPress. I think it’s easier to use and looks better. Posting blog entries is just more fun. The difference compared to before is that now it’s hosted on wordpress.com instead of being self-hosted.

The Old Blog Entries

My old blog items are copied and are still available here: https://blog-static.harald.workers.dev/. It’s missing all dynamic features as it’s a static copy.

For those who are curious how this works: It’s copy of the previous blog via httrack and stored on BackBlaze B2 object storage (copy via MinIO) and served via CloudFlare Workers.

Here the rather simple code. Replace B2BaseUrl and downloadKey with your own values.

// Hosting static web files on BackBlaze's B2

const B2BaseUrl = 'https://f000.backblazeb2.com/file/BUCKET/blog/static/';
const downloadKey = '3_20200112......33_0005_dnld';

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  let response;

  if (request.method !== 'GET') {
    response = new Response('Expect only GET requests', { status: 400 })
  } else {
    let b2Url = request.url.split('/').slice(3).join('/');
    if (b2Url == "" || b2Url == "/") {
            b2Url = "index.html";
    }
    b2Url = B2BaseUrl + b2Url;

    let b2Headers = new Headers(request.headers);
    b2Headers.append("Authorization", downloadKey);
    modRequest = new Request(b2Url, {
        method: request.method,
        headers: b2Headers
    });
    response = await fetch(modRequest);
    // Make the headers mutable by re-constructing the Response.
    response = new Response(response.body, response);
    response.headers.set('Cache-Control', 'max-age=7200')
  }
  return response;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create your website at WordPress.com
Get started
%d bloggers like this: