| 199 | } |
| 200 | |
| 201 | async function sendFile(filePath: string, res: http.ServerResponse): Promise<boolean> { |
| 202 | let stat: Awaited<ReturnType<typeof fsp.stat>>; |
| 203 | try { |
| 204 | stat = await fsp.stat(filePath); |
| 205 | } catch (err) { |
| 206 | const code = (err as NodeJS.ErrnoException).code; |
| 207 | if (code === "ENOENT" || code === "ENOTDIR") return false; |
| 208 | throw err; |
| 209 | } |
| 210 | if (!stat.isFile()) return false; |
| 211 | |
| 212 | const ext = path.extname(filePath).toLowerCase(); |
| 213 | res.writeHead(200, { |
| 214 | "Content-Type": MIME_TYPES[ext] ?? "application/octet-stream", |
| 215 | "Content-Length": String(stat.size), |
| 216 | }); |
| 217 | await pipeline(createReadStream(filePath), res); |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | async function sendIndexFallback(webDist: string, res: http.ServerResponse): Promise<void> { |
| 222 | const indexPath = path.join(webDist, "index.html"); |