This repository contains the example code for the Medium article: "The Ultimate Guide to Cloudflare Workers". In this article, we explore the capabilities of Cloudflare Workers, an edge computing service that allows you to run your code closer to the user.
TThe application has two routes:
/todo
- returns a JSON todo list from an API source./media
- returns a random image from an API source.
- Edge Computing with Cloudflare Workers
- Routing HTTP requests
- Fetching media from external APIs
- Cron-triggered events
- Enhanced security and low-latency
- Node.js
- npm
- Cloudflare account
- Wrangler CLI
-
Clone the Repository
git clone https://github.com/riceyrolling/tight-scene-fe5d.git
-
Navigate to the directory
cd tight-scene-fe5d
-
Install Dependencies
npm install
-
Authenticate Wrangler
wrangler login
-
Deploy to Cloudflare
wrangler deploy
index.js
: Entry point for the worker code.router.js
: Contains routing logic for incoming HTTP requests.routes/
: Directory containing individual route handlers.todoRoute.js
: Route handler for/todo
path.mediaRoute.js
: Route handler for/media
path.
Make an HTTP request to your deployed Cloudflare Worker:
-
To get a TODO item:
GET https://your-cloudflare-worker.your-subdomain.workers.dev/todo
-
To get a random image:
GET https://your-cloudflare-worker.your-subdomain.workers.dev/media
This project is licensed under the MIT License - see the LICENSE file for details.