I'm looking to serve a gzipped file, however all approaches i have currently followed or come up with don't seem to have any effect.
I have a gzipped file with a gz extension in my static assets folder.
Currently I have used the following:
router.get("*.js", (req, res, next) => {
// only if file exists, the substr is to remove /assets in front
if (!fs.existsSync(`/app/service/public/${req.url.substr(7)}.gz`)) {
return next();
}
console.log(`${req.url} -> ${req.url}.gz`);
req.url = `${req.url}.gz`;
res.set("Content-Encoding", "gzip");
res.set("Content-Type", "text/javascript");
next();
});
router.use("/assets", express.static("/app/service/public"));
The file exists and the directory is correctly set, but for someway it doesn't seem to serve the gzip file (neither does it add the correct headers)