@@ -247,3 +247,149 @@ cp -r data/ backup-$(date +%Y%m%d)/
247247```
248248
249249Each file is named ` {key}.json ` and contains the complete workspace state.
250+
251+ # Line-of-Sight Tool - Cloudflare Worker API
252+
253+ A serverless backend for collaborative node editing, running on Cloudflare Workers with KV storage.
254+
255+ ## Why Cloudflare Workers?
256+
257+ - ** Free tier** : 100,000 requests/day
258+ - ** Fast** : Edge deployment worldwide
259+ - ** No server to manage** : Fully serverless
260+ - ** KV Storage included** : 100,000 reads/day, 1,000 writes/day free
261+
262+ ## Quick Setup (5 minutes)
263+
264+ ### 1. Install Wrangler CLI
265+
266+ ``` bash
267+ npm install -g wrangler
268+ ```
269+
270+ ### 2. Login to Cloudflare
271+
272+ ``` bash
273+ wrangler login
274+ ```
275+
276+ This opens a browser to authenticate.
277+
278+ ### 3. Create KV Namespace
279+
280+ ``` bash
281+ cd cloudflare-worker
282+ wrangler kv:namespace create " LOS_DATA"
283+ ```
284+
285+ You'll see output like:
286+ ```
287+ 🌀 Creating namespace with title "los-collab-api-LOS_DATA"
288+ ✨ Success!
289+ Add the following to your configuration file in your kv_namespaces array:
290+ { binding = "LOS_DATA", id = "abc123your-namespace-id" }
291+ ```
292+
293+ ### 4. Update wrangler.toml
294+
295+ Edit ` wrangler.toml ` and replace ` YOUR_KV_NAMESPACE_ID_HERE ` with the ID from step 3:
296+
297+ ``` toml
298+ [[kv_namespaces ]]
299+ binding = " LOS_DATA"
300+ id = " abc123your-namespace-id"
301+ ```
302+
303+ ### 5. Deploy
304+
305+ ``` bash
306+ wrangler deploy
307+ ```
308+
309+ You'll get a URL like: ` https://los-collab-api.YOUR-SUBDOMAIN.workers.dev `
310+
311+ That's your API URL!
312+
313+ ## Usage
314+
315+ Your API is now live. Use it in the Node Manager:
316+
317+ 1 . Open Node Manager
318+ 2 . Click the "Local Only" badge
319+ 3 . Enter your Worker URL: ` https://los-collab-api.YOUR-SUBDOMAIN.workers.dev `
320+ 4 . Click "Create New Key"
321+ 5 . Share the key with collaborators
322+
323+ ## API Endpoints
324+
325+ | Method | URL | Description |
326+ | --------| -----| -------------|
327+ | ` POST ` | ` ?action=newkey ` | Create a new workspace |
328+ | ` GET ` | ` ?key=XXXXXXXXXXXXXXXX ` | Get data for a key |
329+ | ` POST ` | ` ?key=XXXXXXXXXXXXXXXX ` | Save data (JSON body) |
330+ | ` GET ` | ` ?action=status ` | Get server status |
331+
332+ ## Configuration
333+
334+ Edit the ` CONFIG ` object in ` worker.js ` :
335+
336+ ``` javascript
337+ const CONFIG = {
338+ MAX_KEYS : 50 , // Maximum workspaces
339+ MAX_NODES : 400 , // Max nodes per workspace
340+ MAX_GROUPS : 100 , // Max groups per workspace
341+ MAX_JSON_SIZE : 512000 , // 512KB max payload
342+ KEY_LENGTH : 16 , // Key length
343+ };
344+ ```
345+
346+ ## Local Development
347+
348+ Test locally before deploying:
349+
350+ ``` bash
351+ wrangler dev
352+ ```
353+
354+ This starts a local server at ` http://localhost:8787 `
355+
356+ ## Custom Domain (Optional)
357+
358+ 1 . Go to Cloudflare Dashboard → Workers → your worker
359+ 2 . Click "Triggers" → "Custom Domains"
360+ 3 . Add your domain (must be on Cloudflare DNS)
361+
362+ ## Monitoring
363+
364+ View logs in real-time:
365+
366+ ``` bash
367+ wrangler tail
368+ ```
369+
370+ Or check the Cloudflare Dashboard → Workers → your worker → "Logs"
371+
372+ ## Costs
373+
374+ ** Free tier includes:**
375+ - 100,000 requests/day
376+ - 100,000 KV reads/day
377+ - 1,000 KV writes/day
378+
379+ For a small collaboration group, you'll never hit these limits.
380+
381+ ## Troubleshooting
382+
383+ ** "KV namespace not found"**
384+ - Make sure you ran ` wrangler kv:namespace create "LOS_DATA" `
385+ - Make sure you updated ` wrangler.toml ` with the correct ID
386+
387+ ** CORS errors**
388+ - The worker includes CORS headers for all origins
389+ - If you need to restrict origins, edit ` CORS_HEADERS ` in ` worker.js `
390+
391+ ** "Too many workspaces"**
392+ - Default limit is 50 workspaces
393+ - Increase ` MAX_KEYS ` in the config, or delete old workspaces via KV dashboard
394+
395+ -
0 commit comments