A facade that glues different Medium APIs to retrieve a clean and simple API interface to get a Medium user feed.
It contains all the code neccesary to be deployed using Cloudflare Workers.
To get a glance of how easy is to fetch your own Medium Feed, you can simply copy the script.js build file and edit the following line const username = 'alekrumkamp'
to your Medium username.
Then head to cloudflareworkers.com and paste your code in the editor and click the Update
button.
After a few seconds you should be able to see your Medium feed.
Now that we played around it's time to deploy our code to a Cloudflare Worker.
In order to do this you'll need a Cloudflare free account and get a worker namespace.
Once you have an account, you don't need to add a custom domain. Just head to cloudflareworkers.com and click login.
You should now be able to see this:
Click it to go to the next step; selecting your unique workers.dev subdomain:
Now that we have our name space we can create a Worker for it!
Here we will encounter a similar editor to the one present in cloudflareworkers.com. The difference this time is that instead of just toying around with the code, it can run and be deployed in seconds to your Worker subdomain.
Paste the worker/script.js
code from the repository with your username into the editor.
To do so, just click the Save and deploy
button:
Aaand we are done!
Your code will be live after a few seconds on https://{workerName}.{workersSubdomain}.workers.dev
If you'd like to change the name of the worker, at the top left corner you can do so:
Each request brings up to 10 posts. However the next
attribute can be use to retrieve the following 10 entries. Simply call your worker with the query param next
with the value of it.
For example:
Initial Request:
https://medium-feed.alekrumkamp.workers.dev/
Follow up Request:
https://medium-feed.alekrumkamp.workers.dev/?next=1483371523050
Once all posts are fetched, the attribute next
will not longer be present.
You sure can!
In fact, this entire project was done using Wrangler.
Once you get over the hype of using Cloudflare Workers in the playground and need to use code versioning and other tools you'll find that Wrangler becomes really handy to test and deploy in this serverless environment.
You'll notice that I included a custom webpack.config.js
file in the repository.
If you'd like to minify your bundle before deploying, you can do so by simply deleting this file.
However if you are debugging I recommend you don't do so, so you can receive meaningful Error on line X
kind of debugging hints.
After you have added your custom domain to Cloudflare, you can go to the Workers section:
Having launched the editor, head towards Routes
and add one.
Now it's simply a matter of matching a route with its corresponding worker:
Third-party rss2json may be rate limiting your requests. Consider creating a free account with them to obtain your API and then adding the api_key
query param with your API key to the getUserPath
method in UserController.js.
You may be trying to either fetch Medium account or an empty account. Neither of these cases are supported.
Using Cloudflare workers for free lets you use up to 10ms CPU time. Since this service uses some parsing it may exceed it if the user you are fetching has lots of text content.
You may solve this problem by increasing the limit to 10 posts to be fetched on each request inside the object that is being return in graphqlRequestBody.js. However, be aware that if you don't have a Cloudflare Workers Unlimited account request may fail.
All requests have to be fetched from Medium the first time for each Cloudflare cache region. However after initial fetching these will be blazing fast.