Skip to content

Instantly share code, notes, and snippets.

@bogas04
Created October 3, 2015 16:33
Show Gist options
  • Save bogas04/36053fd049dec5af27b0 to your computer and use it in GitHub Desktop.
Save bogas04/36053fd049dec5af27b0 to your computer and use it in GitHub Desktop.
NodeJS Server with deflated response
// NOTE: Relies on ES6 syntax, works on Node 4.0.0 or higher
var zlib = require('zlib');
require('http')
.createServer((req, res) => {
res.writeHead(200, {
'Content-encoding': 'deflate',
'Content-length': zlib.deflateSync(body).length
});
res.write(zlib.deflateSync(body));
})
.listen(1337);
var body = `<!doctype html>
<html>
<head>
<title>gngr test server</title>
</head>
<style>
body {
text-align: center;
padding: 20px 10px;
}
</style>
<body>
<h1><img src="https://gngr.info/media/img/ginger2.png"/> gngr Test Server</h1>
<h2>written in NodeJS</h2>
<h3>Configurable</h3>
<p>You can configure it by sending commandline arguments</p>
<p>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
</body>
</html>`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment