Skip to content

Instantly share code, notes, and snippets.

@henryjameslau
Created April 16, 2020 14:37
Show Gist options
  • Save henryjameslau/cbe1ffe5f7587f495f7ce5446858adaf to your computer and use it in GitHub Desktop.
Save henryjameslau/cbe1ffe5f7587f495f7ce5446858adaf to your computer and use it in GitHub Desktop.
Launch live-server with middleware with gzip content encoding
#!/bin/bash
# bash script to set up a gzip js as middleware for live-server
if test -f gzip.js; then
echo "gzip.js exists, launching live-server"
live-server --middleware="${PWD}/gzip.js"
else
echo "module.exports = function(req, res, next) {
if (req.url.endsWith('.pbf')) {
next();
res.setHeader('Content-Encoding', 'gzip');
} else {
next();
}
}" > "gzip.js"
live-server --middleware="${PWD}/gzip.js"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment