Cloudflare Workers API for Best Auction Minecraft Plugin - provides real-time auction data synchronization and REST API access.
- π Secure Authentication - JWT + API token based authentication
- π Real-time Event Processing - Receive auction events from Minecraft servers
- π Data Synchronization - Bulk sync auction and bid data
- π REST API - Public API for accessing auction data
- β‘ High Performance - Built on Cloudflare Workers Edge
- π Analytics - Server statistics and event tracking
POST /api/auth/register
- Register new userPOST /api/auth/login
- User loginPOST /api/auth/validate
- Validate API tokenPOST /api/auth/tokens
- Create API tokenGET /api/auth/tokens
- List user tokensDELETE /api/auth/tokens/:id
- Delete token
POST /api/events
- Receive auction eventGET /api/events
- Get eventsGET /api/events/:serverId
- Get server eventsGET /api/events/stats
- Get event statistics
Required fields for ITEM_LISTED
events:
{
"seller_uuid": "string (UUID format)",
"seller_name": "string (1-16 chars)",
"item_name": "string",
"item_type": "string",
"quantity": "integer (positive)",
"start_price": "integer (positive)",
"buyout_price": "integer (positive, optional)",
"created_at": "string (ISO datetime)",
"expires_at": "string (ISO datetime)"
}
POST /api/sync
- Batch sync auction data
GET /api/auctions
- Get auctionsGET /api/auctions/:serverId
- Get server auctionsGET /api/auctions/:serverId/:auctionId
- Get specific auctionGET /api/servers
- Get all serversGET /api/servers/:serverId/stats
- Get server statsGET /api/stats
- Get global statistics
- Node.js 18+
- Cloudflare account
- Wrangler CLI
-
Clone and install dependencies:
cd /Users/masafumi_t/Develop/work/minecraft/projects/best_auction_cloud npm install
-
Configure Cloudflare D1 Database:
# Create database wrangler d1 create best-auction-db # Update wrangler.toml with database ID # Copy the database ID to wrangler.toml # Run migrations wrangler d1 migrations apply best-auction-db --local wrangler d1 migrations apply best-auction-db
-
Set environment variables:
# Set JWT secret wrangler secret put JWT_SECRET # Set other environment variables in wrangler.toml
-
Deploy:
# Development npm run dev # Production npm run deploy
JWT_SECRET
- Secret for JWT token signingENVIRONMENT
- Environment (development/production)CORS_ORIGINS
- Allowed CORS origins (comma-separated)RATE_LIMIT_REQUESTS
- Rate limit per windowRATE_LIMIT_WINDOW
- Rate limit window in seconds
The API uses Cloudflare D1 (SQLite) with the following tables:
users
- User accountsapi_tokens
- API authentication tokensauction_events
- Real-time auction eventsauctions
- Current auction statebids
- Auction bidsservers
- Server tracking
- Register/Login with email and password
- Receive JWT token
- Create API tokens for servers
- Use API tokens for server authentication
- Get API token from web dashboard
- Configure token in plugin config
- Plugin uses token for all API requests
curl -X POST https://your-worker.your-domain.workers.dev/api/auth/register \\
-H "Content-Type: application/json" \\
-d '{
"username": "myuser",
"email": "[email protected]",
"password": "securepassword123"
}'
curl -X POST https://your-worker.your-domain.workers.dev/api/auth/tokens \\
-H "Authorization: Bearer <JWT_TOKEN>" \\
-H "Content-Type: application/json" \\
-d '{
"server_id": "my-minecraft-server",
"permissions": "read,write"
}'
curl -X POST https://your-worker.your-domain.workers.dev/api/events \\
-H "Authorization: Bearer <API_TOKEN>" \\
-H "Content-Type: application/json" \\
-d '{
"event_type": "ITEM_LISTED",
"server_id": "my-server",
"timestamp": "2024-01-01T12:00:00Z",
"auction_id": 123,
"data": {
"seller_uuid": "a730b4c5-38e2-4d0c-ad28-588d229030e5",
"seller_name": "Player1",
"item_name": "Diamond Sword",
"item_type": "DIAMOND_SWORD",
"quantity": 1,
"start_price": 1000,
"buyout_price": 2000,
"created_at": "2024-01-01T12:00:00Z",
"expires_at": "2024-01-10T12:00:00Z"
}
}'
curl https://your-worker.your-domain.workers.dev/api/auctions?server_id=my-server \\
-H "Authorization: Bearer <API_TOKEN>"
npm run dev
npm test
npm run build
Configure the Minecraft plugin with:
cloud:
enabled: true
base_url: "https://your-worker.your-domain.workers.dev"
api_token: "your-api-token-here"
server_id: "your-server-id"
- Rate Limiting - Prevents API abuse
- CORS Protection - Configurable origins
- Security Headers - XSS, CSRF protection
- Token Expiration - Configurable token lifetime
- Permission System - Read/write/admin permissions
- Input Validation - Comprehensive request validation
The API provides built-in monitoring through:
- Health check endpoints
- Request/response logging
- Error tracking
- Performance metrics
MIT License - see LICENSE file for details.
For issues and questions:
- Check the documentation
- Review error logs in Cloudflare dashboard
- Create an issue in the repository