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 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 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,10 +155,14 @@ 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 server = http.createServer(async (request, response) => {
await compressionHandler(request, response);
return handler(request, response, config);
});

server.on('error', (err) => {
console.error(error(`Failed to serve: ${err.stack}`));
process.exit(1);
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