Comparing version 8.2.0 to 9.0.0
@@ -8,3 +8,5 @@ #!/usr/bin/env node | ||
const {promisify} = require('util'); | ||
const {URL} = require('url'); | ||
const {parse} = require('url'); | ||
const dns = require('dns'); | ||
const os = require('os'); | ||
@@ -16,4 +18,6 @@ // Packages | ||
const arg = require('arg'); | ||
const {write: copy} = require('clipboardy'); | ||
const handler = require('serve-handler'); | ||
const schema = require('@zeit/schemas/deployment/config-static'); | ||
const boxen = require('boxen'); | ||
@@ -24,2 +28,3 @@ // Utilities | ||
const readFile = promisify(fs.readFile); | ||
const lookup = promisify(dns.lookup); | ||
@@ -60,3 +65,3 @@ const warning = message => chalk`{yellow WARNING:} ${message}`; | ||
By default, {cyan serve} will listen on {bold 0.0.0.0:3000} and serve the | ||
By default, {cyan serve} will listen on {bold 0.0.0.0:5000} and serve the | ||
current working directory on that address. | ||
@@ -81,2 +86,4 @@ | ||
-n, --no-clipboard Do not copy the local address to the clipboard | ||
{bold ENDPOINTS} | ||
@@ -109,3 +116,5 @@ | ||
const url = new URL(str); | ||
// We cannot use `new URL` here, otherwise it will not | ||
// parse the host properly and it would drop support for IPv6. | ||
const url = parse(str); | ||
@@ -130,3 +139,3 @@ switch (url.protocol) { | ||
case 'tcp:': | ||
url.port = url.port || '3000'; | ||
url.port = url.port || '5000'; | ||
return [parseInt(url.port, 10), url.hostname]; | ||
@@ -153,21 +162,60 @@ default: | ||
const startEndpoint = (endpoint, config) => { | ||
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; | ||
server.on('error', err => { | ||
console.error('serve:', err.stack); | ||
console.error(error(`Failed to serve: ${err.stack}`)); | ||
process.exit(1); | ||
}); | ||
server.listen(...endpoint, () => { | ||
server.listen(...endpoint, async () => { | ||
const details = server.address(); | ||
registerShutdown(() => server.close()); | ||
let localAddress = null; | ||
let networkAddress = null; | ||
if (typeof details === 'string') { | ||
console.log(info(`Accepting connections at ${details}`)); | ||
localAddress = details; | ||
} else if (typeof details === 'object' && details.port) { | ||
const address = details.address === '::' ? 'localhost' : details.address; | ||
console.log(info(`Accepting connections at http://${address}:${details.port}`)); | ||
const {address: ip} = await lookup(os.hostname()); | ||
localAddress = `http://${address}:${details.port}`; | ||
networkAddress = `http://${ip}:${details.port}`; | ||
} | ||
if (isTTY && process.env.NODE_ENV !== 'production') { | ||
let message = chalk.green('Serving!'); | ||
if (localAddress) { | ||
const prefix = networkAddress ? '- ' : ''; | ||
const space = networkAddress ? ' ' : ' '; | ||
message += `\n\n${chalk.bold(`${prefix}Local:`)}${space}${localAddress}`; | ||
} | ||
if (networkAddress) { | ||
message += `\n${chalk.bold('- On Your Network:')} ${networkAddress}`; | ||
} | ||
if (clipboard) { | ||
try { | ||
await copy(localAddress); | ||
message += `\n\n${chalk.grey('Copied local address to clipboard!')}`; | ||
} catch (err) { | ||
console.error(error(`Cannot copy to clipboard: ${err.message}`)); | ||
} | ||
} | ||
console.log(boxen(message, { | ||
padding: 1, | ||
borderColor: 'green', | ||
margin: 1 | ||
})); | ||
} else { | ||
console.log(info('Accepting connections')); | ||
const suffix = localAddress ? ` at ${localAddress}` : ''; | ||
console.log(info(`Accepting connections${suffix}`)); | ||
} | ||
@@ -268,2 +316,3 @@ }); | ||
'--config': String, | ||
'--no-clipboard': Boolean, | ||
'-h': '--help', | ||
@@ -275,2 +324,3 @@ '-v': '--version', | ||
'-c': '--config', | ||
'-n': '--no-clipboard', | ||
// This is deprecated and only for backwards-compatibility. | ||
@@ -298,3 +348,3 @@ '-p': '--listen' | ||
// Default endpoint | ||
args['--listen'] = [[3000]]; | ||
args['--listen'] = [[5000]]; | ||
} | ||
@@ -324,3 +374,3 @@ | ||
for (const endpoint of args['--listen']) { | ||
startEndpoint(endpoint, config); | ||
startEndpoint(endpoint, config, args); | ||
} | ||
@@ -327,0 +377,0 @@ |
{ | ||
"name": "serve", | ||
"version": "8.2.0", | ||
"version": "9.0.0", | ||
"description": "Static file serving and directory listing", | ||
@@ -42,6 +42,8 @@ "scripts": { | ||
"arg": "2.0.0", | ||
"boxen": "1.3.0", | ||
"chalk": "2.4.1", | ||
"serve-handler": "3.2.0", | ||
"clipboardy": "1.2.3", | ||
"serve-handler": "3.2.1", | ||
"update-check": "1.5.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14590
290
8
3
2
+ Addedboxen@1.3.0
+ Addedclipboardy@1.2.3
+ Addedansi-align@2.0.0(transitive)
+ Addedansi-regex@3.0.1(transitive)
+ Addedarch@2.2.0(transitive)
+ Addedboxen@1.3.0(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedcli-boxes@1.0.0(transitive)
+ Addedclipboardy@1.2.3(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addedexeca@0.7.00.8.0(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedserve-handler@3.2.1(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@2.1.1(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedterm-size@1.2.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwidest-line@2.0.1(transitive)
+ Addedyallist@2.1.2(transitive)
- Removedserve-handler@3.2.0(transitive)
Updatedserve-handler@3.2.1