package cleanup
This commit is contained in:
parent
e3dccc3a3d
commit
c9794ebaf8
@ -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",
|
||||
|
||||
47
src/serve.js
47
src/serve.js
@ -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');
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user