* @param filename * @param req * @param res * @private
(
filename: string,
req: http.IncomingMessage,
res: http.ServerResponse
)
| 607 | * @private |
| 608 | */ |
| 609 | private static sendFile( |
| 610 | filename: string, |
| 611 | req: http.IncomingMessage, |
| 612 | res: http.ServerResponse |
| 613 | ): void { |
| 614 | const readStream = createReadStream( |
| 615 | path.join(__dirname, "../client-dist/", filename) |
| 616 | ); |
| 617 | const encoding = accepts(req).encodings(["br", "gzip", "deflate"]); |
| 618 | |
| 619 | const onError = (err: NodeJS.ErrnoException | null) => { |
| 620 | if (err) { |
| 621 | res.end(); |
| 622 | } |
| 623 | }; |
| 624 | |
| 625 | switch (encoding) { |
| 626 | case "br": |
| 627 | res.writeHead(200, { "content-encoding": "br" }); |
| 628 | pipeline(readStream, createBrotliCompress(), res, onError); |
| 629 | break; |
| 630 | case "gzip": |
| 631 | res.writeHead(200, { "content-encoding": "gzip" }); |
| 632 | pipeline(readStream, createGzip(), res, onError); |
| 633 | break; |
| 634 | case "deflate": |
| 635 | res.writeHead(200, { "content-encoding": "deflate" }); |
| 636 | pipeline(readStream, createDeflate(), res, onError); |
| 637 | break; |
| 638 | default: |
| 639 | res.writeHead(200); |
| 640 | pipeline(readStream, res, onError); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Binds socket.io to an engine.io instance. |