Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for compression #487

Merged
merged 2 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bin/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ const {write: copy} = require('clipboardy');
const handler = require('serve-handler');
const schema = require('@zeit/schemas/deployment/config-static');
const boxen = require('boxen');
const compression = require('compression');

// Utilities
const pkg = require('../package');

const readFile = promisify(fs.readFile);
const lookup = promisify(dns.lookup);
const compressionHandler = promisify(compression());

const warning = (message) => chalk`{yellow WARNING:} ${message}`;
const info = (message) => chalk`{magenta INFO:} ${message}`;
Expand Down Expand Up @@ -153,9 +155,17 @@ const registerShutdown = (fn) => {
};

const startEndpoint = (endpoint, config, args) => {
const server = http.createServer((request, response) => handler(request, response, config));
const {isTTY} = process.stdout;
const clipboard = args['--no-clipboard'] !== true;
const compress = args['--no-compression'] !== true;

const server = http.createServer(async (request, response) => {
if (compress) {
await compressionHandler(request, response);
}

return handler(request, response, config);
});

server.on('error', (err) => {
console.error(error(`Failed to serve: ${err.stack}`));
Expand Down Expand Up @@ -310,13 +320,15 @@ const loadConfig = async (cwd, entry, args) => {
'--debug': Boolean,
'--config': String,
'--no-clipboard': Boolean,
'--no-compression': Boolean,
'-h': '--help',
'-v': '--version',
'-l': '--listen',
'-s': '--single',
'-d': '--debug',
'-c': '--config',
'-n': '--no-clipboard',
'-u': '--no-compression',
// This is deprecated and only for backwards-compatibility.
'-p': '--listen'
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"boxen": "1.3.0",
"chalk": "2.4.1",
"clipboardy": "1.2.3",
"compression": "1.7.3",
"serve-handler": "5.0.3",
"update-check": "1.5.2"
}
Expand Down
Loading