Skip to content

ic3software/cfworker-json-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Worker JSON Server

A Cloudflare Worker that serves JSON files from R2 storage, with admin endpoints for uploading and deleting files.

Features

  • Serve JSON files directly from R2 storage
  • Admin endpoints for uploading and deleting files
  • Support for presigned URLs for direct browser uploads
  • CORS support for cross-origin requests
  • API key authentication for admin operations

Prerequisites

Setup

  1. Install dependencies:

    npm install
  2. Create an R2 bucket:

    wrangler r2 bucket create json-files
  3. Set your admin API key:

    wrangler secret put ADMIN_API_KEY
  4. Deploy the worker:

    npm run deploy

API Endpoints

Public Endpoints

  • GET /{filename} - Serve a JSON file
  • GET / - API documentation

Admin Endpoints (requires x-api-key header)

  • PUT /upload/{filename} - Upload a JSON file
  • DELETE /delete/{filename} - Delete a JSON file
  • GET /presigned-url/{filename} - Get a presigned URL for direct upload

Usage Examples

Serve a JSON file

curl https://your-worker.your-subdomain.workers.dev/data.json

Upload a JSON file

curl -X PUT \
  -H "x-api-key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"key": "value"}' \
  https://your-worker.your-subdomain.workers.dev/upload/data.json

Delete a JSON file

curl -X DELETE \
  -H "x-api-key: your-api-key" \
  https://your-worker.your-subdomain.workers.dev/delete/data.json

Get a presigned URL for direct upload

curl -H "x-api-key: your-api-key" \
  https://your-worker.your-subdomain.workers.dev/presigned-url/data.json

Development

Run the worker locally:

npm run dev

Security Considerations

  • The admin API key should be kept secure and not committed to version control
  • Consider implementing rate limiting for production use
  • Review CORS settings for your specific use case
  • Consider implementing additional authentication methods for production use

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published