Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-worker-alpha

A minimal Cloudflare Worker that accepts a string over HTTP and saves it to a D1 database, so you can check it later with a query or a curl.

Endpoints

  • POST /save — save a string
    • JSON body: { "value": "some string" }
    • or raw text body with any other content-type
    • optional auth: if SAVE_TOKEN secret is set, send Authorization: Bearer <token>
  • GET /entries — returns the last 50 saved entries as JSON

Setup

This repo is zero-touch: import it into the Cloudflare dashboard (Workers & Pages → Create → Import a repository) and deploy. No manual D1 setup is needed.

  • wrangler.toml omits database_id, so Wrangler auto-provisions a new D1 database named simple-worker-alpha-db and binds it as DB on first deploy.
  • The Worker itself creates the entries table on first request (see ensureSchema() in src/index.js), so there's no separate migration step.

If deploying from the CLI instead of the dashboard:

npm install

# (optional) set a shared secret so only your server can POST
npx wrangler secret put SAVE_TOKEN

# deploy (auto-provisions the D1 database; table is created on first request)
npm run deploy

The db:create / db:migrate:* scripts are kept only as a manual fallback if you ever want an explicit, pre-populated database instead of relying on auto-provisioning + lazy table creation.

Usage

# save a string
curl -X POST https://simple-worker-alpha.<your-subdomain>.workers.dev/save \
  -H "Content-Type: application/json" \
  -d '{"value":"hello world"}'

# with auth enabled
curl -X POST https://simple-worker-alpha.<your-subdomain>.workers.dev/save \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"value":"hello world"}'

# read entries back
curl https://simple-worker-alpha.<your-subdomain>.workers.dev/entries

Save your public IP (handy one-liner, e.g. for testing from Termux)

curl -X POST https://simple-worker-alpha.<your-subdomain>.workers.dev/save \
  -H "Content-Type: application/json" \
  -d "{\"value\":\"$(curl -s ifconfig.me)\"}"

curl https://simple-worker-alpha.<your-subdomain>.workers.dev/entries

Local development

npm run db:migrate:local
npm run dev

About

Simple Cloudflare Worker that saves a string via HTTP POST to D1 and lists entries via GET

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages