Using medium as a backend for our blog.

Elmer Bulthuis
Gameye
Published in
2 min readOct 25, 2019

So we, as many companies, want to have a blog. We use this as a marketing tool for both our developers and clients. Medium seemed the right choice, since they are kind of the standard for blogging and offer some nice features.

But we also want to integrate our blog in our website. At least in the design of our website.

With medium you can design your publication page a bit, but this was nog enough for us. We want to have complete control of how our blog looks and feels.

So we looked into the ?format=json option in medium. Add this to your log url and you get the content of the blog as json. Ideal for including that content in your own website!

But we wanted even more. We wanted a client side only solution so we wouldn’r have to write a backend. Now we cannot get the json from medium in our browser because of CORS headers.

We came up with very simple solution that is basically a proxy that adds the neccessary headers. We do this via NGINX, by using the following configuration:

server {
listen 80 default_server;
location / {
add_header Access-Control-Allow-Origin "*";

proxy_set_header Origin "";
proxy_pass http://medium.gameye.com/gameye/;
}
}

And now we can use the blog-content directly from our client-side applications.

Or, well, the json that you get from medium is actually a bit flaky, it starts with some rubbish. For some reason the json is prefixed with some javascript and an x closing tag, so we cut off everything before the first {. Our code for reading the blog posts looks something like this:

async function fetchBlogData(blogName) {
const response = await fetch("http://blog.gameye.com/" + blogName + "?format=json");
const textData = await response.text();
const data = JSON.parse(textData.substring(textData.indexOf("{")));
return data;
}

happy blog-integrating! :-)

--

--