Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place

add debugging

Changed files
+26
hosting-service
+13
hosting-service/src/lib/utils.ts
··· 268 268 // Allow up to 100MB per file blob, with 2 minute timeout 269 269 let content = await safeFetchBlob(blobUrl, { maxSize: 100 * 1024 * 1024, timeout: 120000 }); 270 270 271 + console.log(`[DEBUG] ${filePath}: fetched ${content.length} bytes, base64=${base64}, encoding=${encoding}, mimeType=${mimeType}`); 272 + 271 273 // If content is base64-encoded, decode it back to binary (gzipped or not) 272 274 if (base64) { 275 + const originalSize = content.length; 273 276 // The content from the blob is base64 text, decode it directly to binary 274 277 const buffer = Buffer.from(content); 275 278 const base64String = buffer.toString('ascii'); // Use ascii for base64 text, not utf-8 279 + console.log(`[DEBUG] ${filePath}: base64 string first 100 chars: ${base64String.substring(0, 100)}`); 276 280 content = Buffer.from(base64String, 'base64'); 281 + console.log(`[DEBUG] ${filePath}: decoded from ${originalSize} bytes to ${content.length} bytes`); 282 + 283 + // Check if it's actually gzipped by looking at magic bytes 284 + if (content.length >= 2) { 285 + const magic = content[0] === 0x1f && content[1] === 0x8b; 286 + const byte0 = content[0]; 287 + const byte1 = content[1]; 288 + console.log(`[DEBUG] ${filePath}: has gzip magic bytes: ${magic} (0x${byte0?.toString(16)}, 0x${byte1?.toString(16)})`); 289 + } 277 290 } 278 291 279 292 const cacheFile = `${CACHE_DIR}/${did}/${site}${dirSuffix}/${filePath}`;
+13
hosting-service/src/server.ts
··· 35 35 const content = readFileSync(cachedFile); 36 36 const metaFile = `${cachedFile}.meta`; 37 37 38 + console.log(`[DEBUG SERVE] ${requestPath}: file size=${content.length} bytes, metaFile exists=${existsSync(metaFile)}`); 39 + 38 40 // Check if file has compression metadata 39 41 if (existsSync(metaFile)) { 40 42 const meta = JSON.parse(readFileSync(metaFile, 'utf-8')); 43 + console.log(`[DEBUG SERVE] ${requestPath}: meta=${JSON.stringify(meta)}`); 44 + 45 + // Check actual content for gzip magic bytes 46 + if (content.length >= 2) { 47 + const hasGzipMagic = content[0] === 0x1f && content[1] === 0x8b; 48 + const byte0 = content[0]; 49 + const byte1 = content[1]; 50 + console.log(`[DEBUG SERVE] ${requestPath}: has gzip magic bytes=${hasGzipMagic} (0x${byte0?.toString(16)}, 0x${byte1?.toString(16)})`); 51 + } 52 + 41 53 if (meta.encoding === 'gzip' && meta.mimeType) { 42 54 // Serve gzipped content with proper headers 55 + console.log(`[DEBUG SERVE] ${requestPath}: serving as gzipped with Content-Encoding header`); 43 56 return new Response(content, { 44 57 headers: { 45 58 'Content-Type': meta.mimeType,