paywall-consumer-server
v1.0.0
Published
Server for consuming the paywall API
Readme
Consumer Proxy Server
The consumer proxy server is a Node.js Express application that acts as an intermediary between the frontend client and the paywall API service, managing API key authentication and providing a clean interface for content consumption.
Architecture
Core Components
- Express Proxy Server - Lightweight Node.js server with CORS support
- API Key Management - Embedded API key handling for paywall service authentication
- Request Proxying - Transparent request forwarding with authentication injection
- Stream Processing - Efficient streaming of video and image content
- Error Handling - Comprehensive error management and client feedback
Features
Proxy Functionality
- Transparent Proxying - Seamlessly forwards requests to paywall API
- Authentication Injection - Automatically adds API keys to paywall requests
- Stream Support - Efficiently streams large video files without memory buffering
- Error Translation - Converts paywall API errors to client-friendly responses
Content Support
- HTML Content - Proxy HTML articles and documents
- Image Streaming - Stream images with proper content headers
- Video Streaming - Support for segmented video delivery with range requests
- Content Listing - Proxy content catalog and duration options
Configuration Management
- Environment Variables - Configurable paywall API endpoint and port
- API Key Storage - Secure API key management for paywall authentication
- Request Timeout - Configurable timeout for paywall requests
- CORS Configuration - Flexible cross-origin request handling
API Endpoints
All endpoints proxy to the corresponding paywall API endpoints:
Content Management
GET /api/content/list- List all available contentGET /api/content/durations- Get available duration options
Content Delivery
GET /api/html/:id- Proxy HTML content from paywallGET /api/image/:id- Stream image content with proper headersGET /api/video/:id- Stream video segments with range support
Video Control
DELETE /api/video/:id/progress- Reset video progress
System
GET /health- Health check endpoint
Configuration
Environment variables:
PORT- Server port (default: 4006)PAYWALL_API_URL- Paywall service endpoint (default: http://localhost:4005)API_KEY- API key for paywall authentication (default: test-key-123)REQUEST_TIMEOUT- Request timeout in milliseconds
Development
# Install dependencies
npm install
# Development server with auto-reload
npm run dev
# Production server
npm startArchitecture Benefits
Security
- API Key Encapsulation - Frontend never needs to know paywall API keys
- Request Validation - Server-side validation of requests before proxying
- Error Sanitization - Prevents sensitive paywall error details from reaching client
Performance
- Stream Processing - Videos and images streamed without memory buffering
- Connection Pooling - Efficient HTTP connection reuse to paywall API
- Request Optimization - Single hop between frontend and proxy
Maintainability
- Clean Separation - Clear separation between client and paywall concerns
- Centralized Configuration - Single point for API endpoint and key management
- Modular Design - Easy to extend with additional proxy functionality
Request Flow
- Client Request - Frontend makes request to proxy server
- Authentication - Proxy adds API key header for paywall authentication
- Forwarding - Request forwarded to paywall service with authentication
- Response Processing - Paywall response processed and streamed back to client
- Error Handling - Any errors converted to client-appropriate responses
Stream Management
- Automatic Cleanup - Stream resources automatically cleaned up on client disconnect
- Memory Efficiency - Large files streamed without loading into memory
- Range Request Support - HTTP range requests passed through for video seeking
- Content Headers - Proper content-type and caching headers maintained
