Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 2.49 KB

File metadata and controls

59 lines (37 loc) · 2.49 KB

Server Module Files

This module provides the backend infrastructure for api-ape's WebSocket-based Remote Procedure Events (RPE) system. It transforms standard HTTP servers into real-time API servers with automatic controller routing.

Guidelines

  • Multi-runtime support — Code must work on Node.js, Bun, and Deno; use runtime detection via lib/wsProvider.js
  • Zero dependencies — Avoid external packages; use built-in WebSocket polyfill when native unavailable
  • JSS encoding — Always use utils/jss for message serialization to preserve extended types
  • Controller context — Controllers receive this context with clientId, broadcast, send, and embedded data
  • Binary transfers — Use the tag system (<!B>, <!A>, <!F>) for file handling

Directory Structure

server/
├── index.js      # Entry point (exports lib/main)
├── client/       # Server-side client (index.js + connection management)
├── lib/          # Core server implementation
├── plugins/      # Binary data handling plugins
├── adapters/     # 🌲 Forest distributed mesh adapters
├── socket/       # WebSocket message handlers
├── security/     # Origin validation & CSRF protection
└── utils/        # Server utilities

Files

index.js

Main entry point that re-exports the ape initializer from lib/main.js. This is what users get when they require('api-ape') or import { ape } from 'api-ape'.

client/

Server-side WebSocket client module for outbound connections. Contains the main client (index.js) and connection management. See client/files.md.

lib/

Core server implementation including initialization, controller loading, broadcasting, and WebSocket handling. See lib/files.md.

plugins/

Binary data handling utilities. See plugins/files.md.

adapters/

Database adapters for the Forest distributed mesh system (Redis, MongoDB, PostgreSQL, Supabase, Firebase). See adapters/files.md.

socket/

WebSocket message handlers for connection validation, incoming message processing, and response serialization. See socket/files.md.

security/

Origin validation and CSRF protection for WebSocket connections. See security/files.md.

utils/

Server utilities including controller loading, ID generation, and User-Agent parsing. See utils/files.md.