Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikaelvesavuori/cloudflare-workers-demos
Assorted demos for how to use Cloudflare Workers
https://github.com/mikaelvesavuori/cloudflare-workers-demos
cloudflare-workers demos edge-functions edge-logic serverless serverless-functions
Last synced: 2 months ago
JSON representation
Assorted demos for how to use Cloudflare Workers
- Host: GitHub
- URL: https://github.com/mikaelvesavuori/cloudflare-workers-demos
- Owner: mikaelvesavuori
- Archived: true
- Created: 2019-11-22T06:35:54.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-27T20:06:02.000Z (about 5 years ago)
- Last Synced: 2024-08-03T03:04:04.587Z (6 months ago)
- Topics: cloudflare-workers, demos, edge-functions, edge-logic, serverless, serverless-functions
- Language: JavaScript
- Size: 13.7 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Demos for Cloudflare Workers
Assorted demos for doing things with [Cloudflare Workers](https://workers.cloudflare.com).
Examples are:
- Render a complete webpage at the edge
- A/B testing
- Check if the user is a bot or crawler and set that value as a header
- Check if the user is on a mobile device and set that value as a header
- Check the user's country and set that value as a header## What are edge functions/workers?
Workers let you do _edge logic_ which means:
- You can do things with your code before even hitting any other servers
- It's very fast since the compute happens at one of Cloudflare's almost 200 data centers (probably very close to you!)
- Frankly you can do lots of things with it since it's just plain JavaScript!
- But my favorite: It gives you some of those "server"ful headers and things back to any of your serverless implementationsOn Cloudflare, these serverless edge functions are also extremely fast (according to them, up to 50x faster). Having worked quite a bit with serverless across the big three providers, I can attest that Cloudflare Workers are the fastest you will get if you need serverless compute.
## Use cases
I can imagine a LOT of use cases, but for my part I'm seeing these in particular:
- As a complete, serverless backend for low-compute purposes (push something to a database, add a user, send email...)
- As an extremely lightweight webserver
- As a way to proxy other, "real" webservers and giving them edge-side headers (like country, device and checking if they are a bot) before actually rendering them — _still testing this out_## Limitations
There's a few limitations as well:
- The free plan supports up to 10ms of compute; paid plan does 50ms; you don't have a lot of time to operate with
- If you use Serverless Framework, that plugin may still be wonky for the `.dev` sites (the ones you get out of the box)## How to use the code
You will have to have a [Cloudflare account (free)](https://workers.cloudflare.com) and you can get the regular Workers plan for free as well. You receive a free `{DOMAIN}.workers.dev` domain where the functions will be hosted.
You could use Serverless Framework to deploy code, but the absolutely easiest way is just to log in to Cloudflare and use the panels. Note that Safari is not fully supported, but Chrome works just fine, if you intend to use the inline coding and preview functionality.
For actually getting started, it's all really easy, and covered well in the [docs](https://developers.cloudflare.com/workers/).
## Similar products
- [Akamai EdgeWorkers](https://developer.akamai.com/akamai-edgeworkers-overview)
- [Amazon Web Services Lambda@Edge](https://aws.amazon.com/lambda/edge/)
- [IBM CIS Edge Functions](https://cloud.ibm.com/docs/infrastructure/cis?topic=cis-edge-functions)## References
- [Cloudflare Workers: Template Gallery](https://developers.cloudflare.com/workers/templates/)