* @param filename * @param req * @param res * @private
(
filename: string,
req: IncomingMessage,
res: ServerResponse,
)
| 682 | * @private |
| 683 | */ |
| 684 | private static sendFile( |
| 685 | filename: string, |
| 686 | req: IncomingMessage, |
| 687 | res: ServerResponse, |
| 688 | ): void { |
| 689 | const readStream = createReadStream( |
| 690 | path.join(__dirname, "../client-dist/", filename), |
| 691 | ); |
| 692 | const encoding = accepts(req).encodings(["br", "gzip", "deflate"]); |
| 693 | |
| 694 | const onError = (err: NodeJS.ErrnoException | null) => { |
| 695 | if (err) { |
| 696 | res.end(); |
| 697 | } |
| 698 | }; |
| 699 | |
| 700 | switch (encoding) { |
| 701 | case "br": |
| 702 | res.writeHead(200, { "content-encoding": "br" }); |
| 703 | pipeline(readStream, createBrotliCompress(), res, onError); |
| 704 | break; |
| 705 | case "gzip": |
| 706 | res.writeHead(200, { "content-encoding": "gzip" }); |
| 707 | pipeline(readStream, createGzip(), res, onError); |
| 708 | break; |
| 709 | case "deflate": |
| 710 | res.writeHead(200, { "content-encoding": "deflate" }); |
| 711 | pipeline(readStream, createDeflate(), res, onError); |
| 712 | break; |
| 713 | default: |
| 714 | res.writeHead(200); |
| 715 | pipeline(readStream, res, onError); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Binds socket.io to an engine.io instance. |