A demo project for integrating Cloudflare Workers and libsql-client.
This demo project implements a simple per-location counter. Each visit of the page bumps a counter associated with the location of the Cloudflare Worker instance that ran the particular request.
All visited locations are also visualized with the help of Mappa.
To prepare the environment, set up Cloudflare Workers' wrangler
tool:
https://developers.cloudflare.com/workers/wrangler/install-and-update/
To set up the database, first join the beta for ChiselStrike Turso: https://chiselstrike.com/
Then, create your database and create the following entries in .dev.vars
file, or register them
as secrets on Cloudflare.
LIBSQL_CLIENT_URL = "https://<YOUR-DB-URL-HERE>"
LIBSQL_CLIENT_USER = "<YOUR-USERNAME-HERE>"
LIBSQL_CLIENT_PASS = "<YOUR-PASS-HERE>"
To run the example:
- Run
wrangler dev
- Visit your page at localhost:8787
The example is also deployed live here: https://country-counter.p-sarna.workers.dev/