| 297 | * derived from `req.url`. |
| 298 | */ |
| 299 | const collectServableFiles = (): Map<string, string> => { |
| 300 | const map = new Map<string, string>(); |
| 301 | |
| 302 | const walk = (dir: string): void => { |
| 303 | if (!fs.existsSync(dir)) { |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { |
| 308 | const abs = path.join(dir, entry.name); |
| 309 | |
| 310 | if (entry.isDirectory()) { |
| 311 | walk(abs); |
| 312 | } else if (entry.isFile()) { |
| 313 | const rel = path.relative(PREVIEW_DIR, abs).split(path.sep).join("/"); |
| 314 | |
| 315 | map.set(`/${rel}`, abs); |
| 316 | } |
| 317 | } |
| 318 | }; |
| 319 | |
| 320 | walk(PREVIEW_DIR); |
| 321 | |
| 322 | return map; |
| 323 | }; |
| 324 | |
| 325 | const CONTENT_TYPES: Record<string, string> = { |
| 326 | ".html": "text/html", |