| 125 | } |
| 126 | |
| 127 | async function appendToLog( |
| 128 | logPath: string, |
| 129 | label: string, |
| 130 | data?: unknown |
| 131 | ): Promise<void> { |
| 132 | const timestamp = new Date().toISOString(); |
| 133 | const line = |
| 134 | data !== undefined |
| 135 | ? `[${timestamp}] ${label} | ${JSON.stringify(data)}\n` |
| 136 | : `[${timestamp}] ${label}\n`; |
| 137 | const file = Bun.file(logPath); |
| 138 | const existing = (await file.exists()) ? await file.text() : ""; |
| 139 | await Bun.write(logPath, existing + line); |
| 140 | } |
| 141 | |
| 142 | const corsHeaders = { |
| 143 | "Access-Control-Allow-Origin": "*", |