const compression = require('compression');

const compress = compression({
	level: 6, // Balance speed vs. ratio (1-9)
	threshold: 512, // Compress only if response >512 bytes to avoid overhead on small bundles
	filter: (req, res) => { // Ensure bundles are compressed
		const accept = req.get("Accept");
		if (accept.startsWith("application/vnd.aaltronav.dougal+octet-stream")) return true;
		if (accept.includes("json")) return true;
		if (accept.startsWith("text/")) return true;
		if (accept.startsWith("model/obj")) return true;

		// fallback to standard filter function
		return compression.filter(req, res)
	}
});

module.exports = compress;
