Public
Like
registry
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v197View latest version
A comprehensive file management system for Val Town that handles different file types including HTTP, cron, email, JSON, and more with collaborative editing capabilities.
- Multi-file type support: HTTP, cron, email, JSON, TypeScript, and more
- Collaborative editing: Real-time collaboration using YJS with ts-editor component
- TypeScript editor: Full-featured TypeScript editor with syntax highlighting
- File type detection: Automatic file type detection and appropriate handling
- KV-based storage: Simple and reliable KV storage for all data
- Configurable URLs: All service URLs are configurable via config.json
-
Sync Service (
/sync):- Periodically syncs Val Town files to KV storage
- Stores val metadata, file metadata, and file content separately
- Simple and reliable data persistence
-
HTTP Services (
/zons,/zon,/file):- Direct KV access: All handlers read directly from KV storage
- Fast and simple: No complex middleware or fallback logic
- Reliable: KV storage is always available and consistent
- Simplicity: Single data source eliminates complexity
- Reliability: KV storage is persistent and always available
- Performance: Direct KV access is fast and predictable
- Maintainability: Clean, straightforward code without complex abstractions
├── config.json # Configuration file with URLs and file type definitions
├── zons # Main gallery view showing all zons (HTTP)
├── zon # Individual zon view with file listings (HTTP)
├── file # File editor interface with TypeScript support (HTTP)
├── sync # Background sync service for YJS collaboration (Cron)
└── README.md # This file
The system uses /config.json for configuration:
{ "urls": { "zons": "https://zons.val.run", // Main gallery URL "zon": "https://zon.val.run", // Individual zon view URL "files": "https://svc.val.run" // File editor URL }, "editor": { "yjs": { "room": "@vals", // YJS collaboration room "url": "wss://hp.cfapps.us10-001.hana.ondemand.com" // YJS WebSocket URL } }, "fileTypes": { // File type definitions with icons, colors, templates, etc. } }
- HTTP (
http) - Web endpoints and APIs - Cron (
cron) - Scheduled tasks - Email (
email) - Email handlers - JSON (
json) - Configuration and data files - TypeScript (
ts) - General TypeScript files - JavaScript (
js) - JavaScript files - Markdown (
md) - Documentation files
GET /- Main gallery showing all zons- Displays all available zons with metadata
GET /- Redirects to main galleryGET /{zon-name}- View files in specific zonGET /{zon-name}/files- API endpoint returning JSON list of files- Groups files by type and shows file metadata
GET /- Redirects to main gallery (configurable)GET /{zon-name}/{file-name}- Edit specific file with ts-editorGET /{zon-name}/{file-name}/raw- Get raw file content as JSONPOST /{zon-name}/{file-name}- Save file changes
- Cron job that syncs Val Town files to YJS documents
- Enables real-time collaborative editing
- Runs periodically to keep YJS documents up to date
- Browse zons: Visit main gallery to see all available zons
- Select zon: Click on a zon to view its files grouped by type
- Edit file: Click on a file to open it in the collaborative editor
- Save changes: Use the Save button to persist changes back to Val Town
- Run HTTP files: Use the Run button to test HTTP endpoints
The system integrates with:
- Yjs: Primary data source for real-time collaborative editing
- KV Storage: Backup data source when Yjs is not available or still connecting
- ts-editor: For TypeScript/JavaScript editing with syntax highlighting
- Sync Service: Periodically syncs Val Town files to KV storage
- HTTP Services: Read directly from KV storage for all data needs
- Editor Integration: ts-editor still provides collaborative editing via Yjs
val:{valName}- Val metadata (name, id, files list, etc.)file:{valName}:{fileName}- File metadata (type, path, etc.)content:{valName}:{fileName}- File content (up to 1MB per file)
Each HTTP service directly accesses KV storage:
- No complex middleware or fallback logic
- Direct KV reads for fast, predictable performance
- Clean separation of concerns
- Easy to understand and maintain
- All URLs are configurable via
config.json - File types can be extended by adding to the
fileTypesconfiguration - Authorization is currently disabled for development (returns true)
- Error handling includes proper error propagation and user feedback