Adding Simple Routing to Cloudflare Workers

I’ve been "playing" with serverless for years now, but honestly still feel new to it. When it comes to organization in a project that uses serverless functions, I’ve typically tried to build one function per operation. So for example, if I had a need to get a list of cats, I’d have one function. If I had a need to get information about a cat based on an identifier, I’d probably build a second one. That being said, I recently came across an example Cloudflare function that did something cool – it used a router, specifically the very lightweight itty-router. Let me share an example of how it works. What is a Router? # So I kinda assume most folks know what... more →
Posted in: JavaScript

Building a Generic RSS Parser Service with Cloudflare Workers

About once every three months I’ll write a quick JavaScript demo and attempt to fetch someone’s RSS feed… and then remember that the vast majority of RSS feeds don’t specify a CORS header to allow remote scripts to load them. I know this – and yet I still tend to forget. I thought it would be kind of fun to build a serverless API via Cloudflare Workers to handle loading, parsing, and returning a RSS feed with CORS allowed. I figured this would be pretty easy, but I ran into a snag right away. Workers and NPM Modules # Cloudflare Workers is Node.js compatible… with some issues. Cloudflare has a documentation page on it addressing what you may run into, and for... more →
Posted in: JavaScript

Using Cloudflare’s AI Workers to Add Translations to PDFs

Late last month, Cloudflare announced new AI features in their (already quite stellar)Workers platform. I’ve been a big fan of their serverless feature (see my earlier posts) so I was quite excited to give this a try myself. Before I begin, I’ll repeat what the Cloudflare folks said in their announcement: "Usage is not currently recommended for production apps". So with that in mind, remember that what I’m sharing today may change in the future. The Demo # Before I get into the code, let me share what I’ve built. Now, at the time I wrote this, Cloudflare’s AI stuff was still in beta and there is no cost yet for using the features. This is, obviously, going... more →
Posted in: JavaScript

Connecting Cloudflare Workers with Service Bindings

I’ll warn you ahead of time and say this post isn’t too much more than what you can find in the documentation, but I wanted to see it work for myself so I had to setup a test locally. Cloudflare Service bindings are a way for one Worker to connect to another. That seems simple enough, but while it defines a "connection", that connection is completely internal to the Cloudflare environment. I.e., incredibly fast with much lower latency. Let’s consider a simple example. The Receiver # I began by creating a worker, named backworker, with just a simple message: export default { async fetch(request, env, ctx) { return new Response('Hello from Backworker'); },}; The Front... more →
Posted in: JavaScript