Socket
Socket
Sign inDemoInstall

serve

Package Overview
Dependencies
Maintainers
4
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serve - npm Package Compare versions

Comparing version 8.2.0 to 9.0.0

74

bin/serve.js

@@ -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 @@

6

package.json
{
"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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc