all repos — homestead @ c2d2170e094464dda332374ddd85ad1a7b763226

Code for my website

Fix serving pre-compressed files

Alan Pearce
commit

c2d2170e094464dda332374ddd85ad1a7b763226

parent

fb61cc0f6b61a64bd4503cbf572f514a9fb3d10c

1 file changed, 6 insertions(+), 12 deletions(-)

jump to
M src/app.tssrc/app.ts
@@ -165,30 +165,24 @@ });
const encodings = (request.headers.get("accept-encoding") || "") .split(",") .map((x) => x.trim().toLowerCase()); - if (encodings.includes("br") && files.has(file.relPath + ".br")) { + if (encodings.includes("br") && files.has(pathname + ".br")) { transaction.setHttpStatus(200); transaction.setTag("http.content-encoding", "br"); - return serveFile(files.get(file.relPath + ".br"), 200, { + return serveFile(files.get(pathname + ".br"), 200, { "content-encoding": "br", "content-type": file.type, }); - } else if ( - encodings.includes("zstd") && - files.has(file.relPath + ".zst") - ) { + } else if (encodings.includes("zstd") && files.has(pathname + ".zst")) { transaction.setHttpStatus(200); transaction.setTag("http.content-encoding", "zstd"); - return serveFile(files.get(file.relPath + ".zst"), 200, { + return serveFile(files.get(pathname + ".zst"), 200, { "content-encoding": "zstd", "content-type": file.type, }); - } else if ( - encodings.includes("gzip") && - files.has(file.relPath + ".gz") - ) { + } else if (encodings.includes("gzip") && files.has(pathname + ".gz")) { transaction.setHttpStatus(200); transaction.setTag("http.content-encoding", "gzip"); - return serveFile(files.get(file.relPath + ".gz"), 200, { + return serveFile(files.get(pathname + ".gz"), 200, { "content-encoding": "gzip", "content-type": file.type, });