itwillsync 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3776,6 +3776,7 @@ function findAvailablePort(startPort) {
3776
3776
  import { createServer as createServer2 } from "http";
3777
3777
  import { readFile } from "fs/promises";
3778
3778
  import { join, extname } from "path";
3779
+ import { gzipSync } from "zlib";
3779
3780
 
3780
3781
  // ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/wrapper.mjs
3781
3782
  var import_stream = __toESM(require_stream(), 1);
@@ -3794,14 +3795,34 @@ var MIME_TYPES = {
3794
3795
  ".png": "image/png",
3795
3796
  ".ico": "image/x-icon"
3796
3797
  };
3797
- async function serveStaticFile(webClientPath, filePath, res) {
3798
+ var COMPRESSIBLE = /* @__PURE__ */ new Set([".html", ".js", ".css", ".json", ".svg"]);
3799
+ var gzipCache = /* @__PURE__ */ new Map();
3800
+ async function serveStaticFile(webClientPath, filePath, req, res) {
3798
3801
  const fullPath = join(webClientPath, filePath);
3799
3802
  const ext = extname(fullPath);
3800
3803
  const contentType = MIME_TYPES[ext] || "application/octet-stream";
3801
3804
  try {
3802
- const content = await readFile(fullPath);
3803
- res.writeHead(200, { "Content-Type": contentType });
3804
- res.end(content);
3805
+ const raw = await readFile(fullPath);
3806
+ const acceptsGzip = (req.headers["accept-encoding"] || "").includes("gzip");
3807
+ if (acceptsGzip && COMPRESSIBLE.has(ext)) {
3808
+ let compressed = gzipCache.get(fullPath);
3809
+ if (!compressed) {
3810
+ compressed = gzipSync(raw);
3811
+ gzipCache.set(fullPath, compressed);
3812
+ }
3813
+ res.writeHead(200, {
3814
+ "Content-Type": contentType,
3815
+ "Content-Encoding": "gzip",
3816
+ "Content-Length": compressed.length
3817
+ });
3818
+ res.end(compressed);
3819
+ } else {
3820
+ res.writeHead(200, {
3821
+ "Content-Type": contentType,
3822
+ "Content-Length": raw.length
3823
+ });
3824
+ res.end(raw);
3825
+ }
3805
3826
  } catch {
3806
3827
  res.writeHead(404, { "Content-Type": "text/plain" });
3807
3828
  res.end("Not Found");
@@ -3820,7 +3841,7 @@ function createSyncServer(options) {
3820
3841
  if (pathname === "/") {
3821
3842
  pathname = "/index.html";
3822
3843
  }
3823
- await serveStaticFile(webClientPath, pathname, res);
3844
+ await serveStaticFile(webClientPath, pathname, req, res);
3824
3845
  });
3825
3846
  const wssServer = new import_websocket_server.default({ noServer: true });
3826
3847
  httpServer.on("upgrade", (req, socket, head) => {