Decentralized web hosting on 0G Storage with Fluence-powered subdomain routing & instant deployment
This project creates a complete decentralized web hosting platform that combines 0G Storage's distributed file system with Fluence's decentralized compute network to enable seamless web application deployment and access.
The system allows developers to:
Core Technology Stack: Storage Layer:
0G Storage Network: Decentralized storage infrastructure for hosting all static assets, metadata, and project files 0G Storage Client (Go): Command-line tool for uploading files and retrieving root hashes from the distributed network Compute Layer:
Fluence Network: Decentralized compute platform handling server-side logic, metadata queries, and dynamic content serving Fluence Aqua: Programming language for writing distributed services that fetch and process root address JSONs Application Layer:
Node.js: Backend runtime for deployment automation and proxy server infrastructure Express.js: Web framework powering the subdomain routing system at *.0gpages.dev Architecture & Data Flow:
JavaScript
Build → Upload Individual Files → Generate Metadata JSON → Upload Metadata → Register Domain The deployment script orchestrates a complex multi-step process:
Compiles production assets from source code Uploads each file individually to 0G Storage using the Go client Captures root hashes for every uploaded file Generates comprehensive metadata JSON mapping file paths to their 0G root hashes Uploads the metadata JSON itself to get the final project root hash Registers the project in both local registry and Fluence network 2. Fluence Integration Architecture:
PlainText
Client Request → Fluence Service → 0G Storage Query → JSON Response → Content Delivery Fluence services act as the "serverless backend":
Metadata Service: Fetches project structure JSONs from 0G Storage using root hashes File Resolution Service: Maps file paths to their individual 0G Storage addresses Caching Service: Implements distributed caching across Fluence nodes for performance Health Check Service: Monitors 0G Storage node availability and switches endpoints 3. Domain Resolution System: Instead of localhost, we implemented a full DNS-based system:
Subdomain Parsing: roothash.0gpages.dev requests are intercepted by our Express server Root Hash Extraction: Custom middleware extracts the 64-character hex root hash from subdomains Fluence Query: Server queries Fluence network for project metadata using the root hash Dynamic Reconstruction: Files are downloaded from 0G Storage and served as a complete web application Partner Technology Benefits: 0G Storage Advantages:
True Decentralization: No single point of failure, files distributed across multiple nodes Cryptographic Integrity: Each file has a unique root hash ensuring tamper-proof storage Cost Efficiency: Pay-once storage model vs. recurring hosting fees Censorship Resistance: Immutable storage that can't be taken down by centralized authorities Fluence Network Benefits:
Serverless Backend: No need to maintain traditional servers for metadata processing Global Distribution: Fluence nodes worldwide ensure low-latency responses Fault Tolerance: If one Fluence node fails, others automatically handle requests Programmable Logic: Aqua scripts enable complex server-side operations without centralized infrastructure Notable Hacks & Technical Innovations:
JavaScript
// Extract 0x-prefixed hash from subdomainconst rootHash = req.get('host').split('.')[0];if (!/^0x[a-fA-F0-9]{64}$/.test(rootHash)) { return res.status(400).send('Invalid root hash format');} 2. Hybrid File Reconstruction: We built a sophisticated caching system that:
Downloads files on-demand from 0G Storage Reconstructs the original directory structure locally Serves files with correct MIME types and headers Implements intelligent prefetching for linked resources 3. Fluence-0G Bridge: Created custom Aqua services that:
aqua
service MetadataResolver("metadata"): getProjectStructure(rootHash: string) -> ProjectMetadata resolveFilePath(rootHash: string, path: string) -> FileInfo cacheProjectData(rootHash: string, metadata: ProjectMetadata) 4. Dynamic DNS Management:
Wildcard DNS configuration for *.0gpages.dev pointing to our infrastructure Real-time subdomain validation and routing Automatic HTTPS certificate generation for all subdomains 5. Build System Integration:
Bash
Run
The build system automatically:
Detects project type (React, Vue, vanilla HTML, etc.) Optimizes assets for decentralized delivery Generates service worker for offline functionality Creates manifest files for PWA compatibility 6. Error Handling & Fallbacks:
0G Storage Failover: If primary nodes are down, automatically switches to backup indexers Fluence Redundancy: Multiple Fluence services handle the same requests for reliability Graceful Degradation: If metadata can't be fetched, serves a basic file listing Cache Warming: Proactively downloads popular projects to reduce load times 7. Performance Optimizations:
Parallel Downloads: Fetches multiple files simultaneously from 0G Storage Compression: Gzip compression for all text-based assets CDN Integration: Fluence nodes act as a distributed CDN Smart Caching: LRU cache with size limits and TTL expiration This architecture essentially creates a "decentralized Vercel" where the entire hosting infrastructure is distributed across 0G Storage and Fluence networks, with no single point of failure or centralized control.

