package cleanup
This commit is contained in:
parent
e3dccc3a3d
commit
c9794ebaf8
@ -13,7 +13,7 @@
|
|||||||
],
|
],
|
||||||
"repository": "vercel/serve",
|
"repository": "vercel/serve",
|
||||||
"bin": {
|
"bin": {
|
||||||
"serve": "./bin/serve.js"
|
"serve": "./src/serve.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"now",
|
"now",
|
||||||
@ -45,6 +45,7 @@
|
|||||||
},
|
},
|
||||||
"git": {},
|
"git": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@plastichub/fs": "^0.13.26",
|
||||||
"@zeit/schemas": "2.6.0",
|
"@zeit/schemas": "2.6.0",
|
||||||
"ajv": "6.12.6",
|
"ajv": "6.12.6",
|
||||||
"arg": "2.0.0",
|
"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 https = require('https');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const {promisify} = require('util');
|
const {
|
||||||
const {parse} = require('url');
|
promisify
|
||||||
|
} = require('util');
|
||||||
|
const {
|
||||||
|
parse
|
||||||
|
} = require('url');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
|
||||||
// Packages
|
// Packages
|
||||||
@ -14,7 +18,9 @@ const Ajv = require('ajv');
|
|||||||
const checkForUpdate = require('update-check');
|
const checkForUpdate = require('update-check');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const arg = require('arg');
|
const arg = require('arg');
|
||||||
const {write: copy} = require('clipboardy');
|
const {
|
||||||
|
write: copy
|
||||||
|
} = require('clipboardy');
|
||||||
const handler = require('./server-handler');
|
const handler = require('./server-handler');
|
||||||
const schema = require('@zeit/schemas/deployment/config-static');
|
const schema = require('@zeit/schemas/deployment/config-static');
|
||||||
const boxen = require('boxen');
|
const boxen = require('boxen');
|
||||||
@ -177,7 +183,11 @@ const registerShutdown = (fn) => {
|
|||||||
const getNetworkAddress = () => {
|
const getNetworkAddress = () => {
|
||||||
for (const name of Object.keys(interfaces)) {
|
for (const name of Object.keys(interfaces)) {
|
||||||
for (const interface of interfaces[name]) {
|
for (const interface of interfaces[name]) {
|
||||||
const {address, family, internal} = interface;
|
const {
|
||||||
|
address,
|
||||||
|
family,
|
||||||
|
internal
|
||||||
|
} = interface;
|
||||||
if (family === 'IPv4' && !internal) {
|
if (family === 'IPv4' && !internal) {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
@ -186,7 +196,9 @@ const getNetworkAddress = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const startEndpoint = (endpoint, config, args, previous) => {
|
const startEndpoint = (endpoint, config, args, previous) => {
|
||||||
const {isTTY} = process.stdout;
|
const {
|
||||||
|
isTTY
|
||||||
|
} = process.stdout;
|
||||||
const clipboard = args['--no-clipboard'] !== true;
|
const clipboard = args['--no-clipboard'] !== true;
|
||||||
const compress = args['--no-compression'] !== true;
|
const compress = args['--no-compression'] !== true;
|
||||||
const httpMode = args['--ssl-cert'] && args['--ssl-key'] ? 'https' : 'http';
|
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 sslPass = args['--ssl-pass'];
|
||||||
|
|
||||||
const server = httpMode === 'https'
|
const server = httpMode === 'https' ?
|
||||||
? https.createServer({
|
https.createServer({
|
||||||
key: fs.readFileSync(args['--ssl-key']),
|
key: fs.readFileSync(args['--ssl-key']),
|
||||||
cert: fs.readFileSync(args['--ssl-cert']),
|
cert: fs.readFileSync(args['--ssl-cert']),
|
||||||
passphrase: sslPass ? fs.readFileSync(sslPass) : ''
|
passphrase: sslPass ? fs.readFileSync(sslPass) : ''
|
||||||
}, serverHandler)
|
}, serverHandler) :
|
||||||
: http.createServer(serverHandler);
|
http.createServer(serverHandler);
|
||||||
|
|
||||||
server.on('error', (err) => {
|
server.on('error', (err) => {
|
||||||
if (err.code === 'EADDRINUSE' && endpoint.length === 1 && !isNaN(endpoint[0]) && args['--no-port-switching'] !== true) {
|
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) {
|
if (entry) {
|
||||||
const {public} = config;
|
const {
|
||||||
|
public
|
||||||
|
} = config;
|
||||||
config.public = path.relative(cwd, (public ? path.resolve(entry, public) : entry));
|
config.public = path.relative(cwd, (public ? path.resolve(entry, public) : entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +366,10 @@ const loadConfig = async (cwd, entry, args) => {
|
|||||||
|
|
||||||
if (!validateSchema(config)) {
|
if (!validateSchema(config)) {
|
||||||
const defaultMessage = error('The configuration you provided is wrong:');
|
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)}`);
|
console.error(`${defaultMessage}\n${message}\n${JSON.stringify(params)}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -419,7 +436,9 @@ const loadConfig = async (cwd, entry, args) => {
|
|||||||
|
|
||||||
if (!args['--listen']) {
|
if (!args['--listen']) {
|
||||||
// Default endpoint
|
// Default endpoint
|
||||||
args['--listen'] = [[process.env.PORT || 5000]];
|
args['--listen'] = [
|
||||||
|
[process.env.PORT || 5000]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args._.length > 1) {
|
if (args._.length > 1) {
|
||||||
@ -433,7 +452,9 @@ const loadConfig = async (cwd, entry, args) => {
|
|||||||
const config = await loadConfig(cwd, entry, args);
|
const config = await loadConfig(cwd, entry, args);
|
||||||
|
|
||||||
if (args['--single']) {
|
if (args['--single']) {
|
||||||
const {rewrites} = config;
|
const {
|
||||||
|
rewrites
|
||||||
|
} = config;
|
||||||
const existingRewrites = Array.isArray(rewrites) ? rewrites : [];
|
const existingRewrites = Array.isArray(rewrites) ? rewrites : [];
|
||||||
|
|
||||||
// As the first rewrite rule, make `--single` work
|
// As the first rewrite rule, make `--single` work
|
||||||
|
|||||||
Reference in New Issue
Block a user