ATlast — you'll never need to find your favorites on another platform again. Find your favs in the ATmosphere.
atproto
17
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 74 lines 1.6 kB view raw
1/** 2 * Response utilities for Hono API 3 * Provides consistent JSON response formatting 4 */ 5 6export interface ApiResponse<T = unknown> { 7 success: boolean; 8 data?: T; 9 error?: string; 10 details?: string; 11} 12 13/** 14 * Get CORS headers based on request origin 15 * Supports credentialed requests from extensions and localhost 16 */ 17export function getCorsHeaders(origin?: string): Record<string, string> { 18 // Allow all origins for non-credentialed requests (backward compatibility) 19 if (!origin) { 20 return { 21 "Access-Control-Allow-Origin": "*", 22 }; 23 } 24 25 // Check if origin is allowed for credentialed requests 26 const allowedOrigins = [ 27 "http://localhost:8888", 28 "http://127.0.0.1:8888", 29 "http://localhost:5173", 30 "http://127.0.0.1:5173", 31 "https://atlast.byarielm.fyi", 32 ]; 33 34 const isExtension = 35 origin.startsWith("chrome-extension://") || 36 origin.startsWith("moz-extension://"); 37 const isAllowedOrigin = allowedOrigins.includes(origin); 38 39 if (isExtension || isAllowedOrigin) { 40 return { 41 "Access-Control-Allow-Origin": origin, 42 "Access-Control-Allow-Credentials": "true", 43 }; 44 } 45 46 // Default to wildcard for unknown origins 47 return { 48 "Access-Control-Allow-Origin": "*", 49 }; 50} 51 52/** 53 * Create a success response 54 */ 55export function createSuccessResponse<T>(data: T): ApiResponse<T> { 56 return { 57 success: true, 58 data, 59 }; 60} 61 62/** 63 * Create an error response 64 */ 65export function createErrorResponse( 66 error: string, 67 details?: string, 68): ApiResponse { 69 return { 70 success: false, 71 error, 72 details, 73 }; 74}