package cleanup

This commit is contained in:
lovebird 2021-08-09 12:03:09 +02:00
parent e3dccc3a3d
commit c9794ebaf8
2 changed files with 64 additions and 42 deletions

View File

@ -13,7 +13,7 @@
],
"repository": "vercel/serve",
"bin": {
"serve": "./bin/serve.js"
"serve": "./src/serve.js"
},
"keywords": [
"now",
@ -45,6 +45,7 @@
},
"git": {},
"dependencies": {
"@plastichub/fs": "^0.13.26",
"@zeit/schemas": "2.6.0",
"ajv": "6.12.6",
"arg": "2.0.0",

View File

@ -5,8 +5,12 @@ const http = require('http');
const https = require('https');
const path = require('path');
const fs = require('fs');
const {promisify} = require('util');
const {parse} = require('url');
const {
promisify
} = require('util');
const {
parse
} = require('url');
const os = require('os');
// Packages
@ -14,7 +18,9 @@ const Ajv = require('ajv');
const checkForUpdate = require('update-check');
const chalk = require('chalk');
const arg = require('arg');
const {write: copy} = require('clipboardy');
const {
write: copy
} = require('clipboardy');
const handler = require('./server-handler');
const schema = require('@zeit/schemas/deployment/config-static');
const boxen = require('boxen');
@ -28,9 +34,9 @@ const compressionHandler = promisify(compression());
const interfaces = os.networkInterfaces();
const warning = (message) => chalk`{yellow WARNING:} ${message}`;
const info = (message) => chalk`{magenta INFO:} ${message}`;
const error = (message) => chalk`{red ERROR:} ${message}`;
const warning = (message) => chalk `{yellow WARNING:} ${message}`;
const info = (message) => chalk `{magenta INFO:} ${message}`;
const error = (message) => chalk `{red ERROR:} ${message}`;
const updateCheck = async (isDebugging) => {
let update = null;
@ -53,7 +59,7 @@ const updateCheck = async (isDebugging) => {
console.log(`${chalk.bgRed('UPDATE AVAILABLE')} The latest version of \`serve\` is ${update.latest}`);
};
const getHelp = () => chalk`
const getHelp = () => chalk `
{bold.cyan serve} - Static file serving and directory listing
{bold USAGE}
@ -177,7 +183,11 @@ const registerShutdown = (fn) => {
const getNetworkAddress = () => {
for (const name of Object.keys(interfaces)) {
for (const interface of interfaces[name]) {
const {address, family, internal} = interface;
const {
address,
family,
internal
} = interface;
if (family === 'IPv4' && !internal) {
return address;
}
@ -186,7 +196,9 @@ const getNetworkAddress = () => {
};
const startEndpoint = (endpoint, config, args, previous) => {
const {isTTY} = process.stdout;
const {
isTTY
} = process.stdout;
const clipboard = args['--no-clipboard'] !== true;
const compress = args['--no-compression'] !== true;
const httpMode = args['--ssl-cert'] && args['--ssl-key'] ? 'https' : 'http';
@ -204,13 +216,13 @@ const startEndpoint = (endpoint, config, args, previous) => {
const sslPass = args['--ssl-pass'];
const server = httpMode === 'https'
? https.createServer({
const server = httpMode === 'https' ?
https.createServer({
key: fs.readFileSync(args['--ssl-key']),
cert: fs.readFileSync(args['--ssl-cert']),
passphrase: sslPass ? fs.readFileSync(sslPass) : ''
}, serverHandler)
: http.createServer(serverHandler);
}, serverHandler) :
http.createServer(serverHandler);
server.on('error', (err) => {
if (err.code === 'EADDRINUSE' && endpoint.length === 1 && !isNaN(endpoint[0]) && args['--no-port-switching'] !== true) {
@ -342,7 +354,9 @@ const loadConfig = async (cwd, entry, args) => {
}
if (entry) {
const {public} = config;
const {
public
} = config;
config.public = path.relative(cwd, (public ? path.resolve(entry, public) : entry));
}
@ -352,7 +366,10 @@ const loadConfig = async (cwd, entry, args) => {
if (!validateSchema(config)) {
const defaultMessage = error('The configuration you provided is wrong:');
const {message, params} = validateSchema.errors[0];
const {
message,
params
} = validateSchema.errors[0];
console.error(`${defaultMessage}\n${message}\n${JSON.stringify(params)}`);
process.exit(1);
@ -419,7 +436,9 @@ const loadConfig = async (cwd, entry, args) => {
if (!args['--listen']) {
// Default endpoint
args['--listen'] = [[process.env.PORT || 5000]];
args['--listen'] = [
[process.env.PORT || 5000]
];
}
if (args._.length > 1) {
@ -433,7 +452,9 @@ const loadConfig = async (cwd, entry, args) => {
const config = await loadConfig(cwd, entry, args);
if (args['--single']) {
const {rewrites} = config;
const {
rewrites
} = config;
const existingRewrites = Array.isArray(rewrites) ? rewrites : [];
// As the first rewrite rule, make `--single` work