codebolt-wsproxyserver
v1.0.0
Published
CodeBolt Wrangler WebSocket Server for Cloudflare Workers
Maintainers
Readme
Codebolt Wrangler WebSocket Proxy
This package provides a Cloudflare Worker plus Durable Object that relays WebSocket messages between Codebolt agents and applications. The Durable Object maintains long-lived connections, queues payloads while peers are offline, and exposes a single /proxy endpoint for upgrades.
Installation
# Install dependencies
npm install
# or
pnpm install
# or
yarn installQuick start
Install Wrangler and authenticate with Cloudflare:
npm install -g wrangler wrangler loginStart the proxy locally:
npm run dev # or wrangler devConnect agents/apps to
ws://localhost:8787/proxyand send JSON messages shaped like:{"type":"register","actor":"agent","agentId":"agent-123","appToken":"my-app"}{"type":"register","actor":"app","appToken":"my-app"}{"type":"forward","actor":"agent","agentId":"agent-123","appToken":"my-app","target":"app","payload":{...}}
Deployment
Development Environment
npm run deploy
# or
wrangler deployStaging Environment
npm run deploy:staging
# or
wrangler deploy --env stagingProduction Environment
npm run deploy:production
# or
wrangler deploy --env productionAvailable Scripts
npm run dev- Start the development servernpm run build- Type check the TypeScript codenpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issues automaticallynpm run deploy- Deploy to development environmentnpm run deploy:staging- Deploy to staging environmentnpm run deploy:production- Deploy to production environmentnpm run tail- View real-time logs from the deployed worker
Configuration
The wrangler.toml file contains the configuration for your Cloudflare Worker:
- name: The name of your worker
- main: The entry point file
- compatibility_date: The Cloudflare Workers API compatibility date
- durable_objects: Configuration for Durable Objects
- vars: Environment variables (different per environment)
Update the values in wrangler.toml with your account details before deploying.
Environment Variables
ENVIRONMENT: Set to "development", "staging", or "production"
Project Structure
├── src/
│ ├── durable/
│ │ └── proxyHub.ts # Durable Object implementation
│ ├── index.ts # Main exports
│ ├── types.ts # TypeScript type definitions
│ └── worker.ts # Cloudflare Worker entry point
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── wrangler.toml # Cloudflare Workers configuration
└── README.md # This fileRequirements
- Node.js 18+
- Wrangler CLI 3+
- Cloudflare account
