Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: greggman/servez-cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 049d7017355bc80bf9405cd447d142d1615c2cdd
Choose a base ref
...
head repository: greggman/servez-cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 86d275a1225cbdaaefb9fe2655bf2d7a8b528615
Choose a head ref

Commits on Aug 7, 2021

  1. use servez-lib v2.3.1

    greggman committed Aug 7, 2021
    Copy the full SHA
    301c854 View commit details
  2. 1.11.1

    greggman committed Aug 7, 2021
    Copy the full SHA
    9a256f8 View commit details

Commits on Sep 17, 2021

  1. use servez-lib v2.4.0

    greggman committed Sep 17, 2021
    Copy the full SHA
    167958e View commit details
  2. add unity-hack option

    greggman committed Sep 17, 2021
    Copy the full SHA
    e487043 View commit details
  3. 1.12.0

    greggman committed Sep 17, 2021
    Copy the full SHA
    9424df9 View commit details

Commits on Jan 19, 2022

  1. bump deps

    greggman committed Jan 19, 2022
    Copy the full SHA
    06f945e View commit details
  2. 1.12.1

    greggman committed Jan 19, 2022
    Copy the full SHA
    74518b9 View commit details

Commits on Feb 27, 2022

  1. Add --qr to show QRCode for root url

    This is useful for pulling the root url up on your phone
    greggman committed Feb 27, 2022
    Copy the full SHA
    571a995 View commit details
  2. README

    greggman committed Feb 27, 2022
    Copy the full SHA
    4ca7cfa View commit details
  3. 1.13.0

    greggman committed Feb 27, 2022
    Copy the full SHA
    0f9f267 View commit details
  4. use servez-lib@2.5.0

    greggman committed Feb 27, 2022
    Copy the full SHA
    199ee60 View commit details
  5. 1.13.1

    greggman committed Feb 27, 2022
    Copy the full SHA
    646560f View commit details

Commits on Feb 28, 2022

  1. smaller square QR code

    greggman committed Feb 28, 2022
    Copy the full SHA
    87fe4aa View commit details
  2. 1.13.2

    greggman committed Feb 28, 2022
    Copy the full SHA
    114ea85 View commit details

Commits on Mar 1, 2022

  1. Copy the full SHA
    6724b85 View commit details
  2. 1.13.3

    greggman committed Mar 1, 2022
    Copy the full SHA
    0f40773 View commit details
  3. Copy the full SHA
    bfb739e View commit details
  4. 1.13.4

    greggman committed Mar 1, 2022
    Copy the full SHA
    e61984c View commit details

Commits on Mar 28, 2022

  1. use servez-lib@2.5.2

    greggman committed Mar 28, 2022
    Copy the full SHA
    4093da3 View commit details
  2. 1.13.5

    greggman committed Mar 28, 2022
    Copy the full SHA
    7ed5126 View commit details

Commits on Mar 31, 2022

  1. use servez-lib@2.6.0

    greggman committed Mar 31, 2022
    Copy the full SHA
    68b3a12 View commit details
  2. Copy the full SHA
    bb4ff54 View commit details
  3. 1.14.0

    greggman committed Mar 31, 2022
    Copy the full SHA
    b7471aa View commit details

Commits on Apr 2, 2022

  1. README

    greggman committed Apr 2, 2022
    Copy the full SHA
    300d2bd View commit details
  2. 1.14.1

    greggman committed Apr 2, 2022
    Copy the full SHA
    86d275a View commit details
Showing with 1,027 additions and 135 deletions.
  1. +9 −1 README.md
  2. +65 −22 bin/servez
  3. +825 −0 lib/qrcodegen.js
  4. +122 −105 package-lock.json
  5. +2 −2 package.json
  6. +4 −5 src/server-worker.js
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -44,17 +44,25 @@ Using `npx` you can run servez without installing it first:

* `--dirs` Show folder listings (defaults to `true`, `--no-dirs` to disable)

* `--qr` Show a QR code for the root url of the server. This might help for using servez with a phone.

* `--cors` Include CORS headers (defaults to `true`, `--no-cors` to disable)

* `--local` make serve only accessible from this machine. The default
is to serve publicly. (0.0.0.0 vs 127.0.0.1)
is to serve publicly. (0.0.0.0 vs 127.0.0.1)

* `--index` Display index.html for folders if it exists (defaults to `true`, `--no-index` to disable)

* `--gzip` serve `somefile.gz` in place of `somefile`

* `--brotli` serve `somefile.br` in place of `somefile`

* `--unity-hack` ignore .gz and .br when computing content type. (defaults to `true`, `--no-unity-hack` to disable)

* `--shared-array-buffers` include headers 'Cross-Origin-Opener-Policy': 'same-origin' and 'Cross-Origin-Embedder-Policy': 'require-corp'.

* `--header=<name>:<value>` extra headers to include eg `--header=Content-Language:de-DE'`

* `--robots` Provide a /robots.txt if one does not exist. (defaults to `true`. `--no-robots` to disable)

* `--hidden` Show files that start with `.`
87 changes: 65 additions & 22 deletions bin/servez
Original file line number Diff line number Diff line change
@@ -19,26 +19,46 @@ const log = {
},
};

function genQRCode(s) {

const qr = QrCode.encodeText(s, Ecc.MEDIUM);
const size = qr.size + 2;

const lines = [];
for (let y = -2; y < size; ++y) {
const line = [];
for (let x = -2; x < size; ++x) {
line.push(c[qr.getModule(x, y) ? 'bgBlack' : 'bgWhite'](' '));
}
lines.push(line.join(''));
}
return lines.join('\n');
}

const optionSpec = {
options: [
{ option: 'help', alias: 'h', type: 'Boolean', description: 'displays help' },
{ option: 'port', alias: 'p', type: 'Int', description: 'port', default: '8080' },
{ option: 'version', type: 'Boolean', description: 'print version' },
{ option: 'scan', type: 'Boolean', description: 'scan for open port', default: 'true', },
{ option: 'dirs', type: 'Boolean', description: 'show directory listing', default: 'true', },
{ option: 'cors', type: 'Boolean', description: 'send CORS headers', default: 'true', },
{ option: 'local', type: 'Boolean', description: 'local machine only', default: 'false', },
{ option: 'index', type: 'Boolean', description: 'serve index.html for directories', default: 'true', },
{ option: 'extensions', type: '[String]', description: 'extensions to try if path does not exist', default: '["html"]', },
{ option: 'gzip', type: 'Boolean', description: 'serve .gz files if they exist', default: 'false', },
{ option: 'brotli', type: 'Boolean', description: 'serve .br files if they exist', default: 'false', },
{ option: 'robots', type: 'Boolean', description: 'serve a robots.txt if one does not exist', default: 'true', },
{ option: 'hidden', type: 'Boolean', description: 'show hidden dotfiles', default: 'false', },
{ option: 'username', type: 'String', description: 'username for basic auth' },
{ option: 'password', type: 'String', description: 'password for basic auth' },
{ option: 'ssl', alias: 'S', type: 'Boolean', description: 'enable https (will use fake cert if not specified)', },
{ option: 'cert', alias: 'C', type: 'String', description: 'Path to ssl cert file', },
{ option: 'key', alias: 'K', type: 'String', description: 'Path to ssl key file', },
{ option: 'help', alias: 'h', type: 'Boolean', description: 'displays help' },
{ option: 'port', alias: 'p', type: 'Int', description: 'port', default: '8080' },
{ option: 'version', type: 'Boolean', description: 'print version' },
{ option: 'scan', type: 'Boolean', description: 'scan for open port', default: 'true', },
{ option: 'qr', type: 'Boolean', description: 'print QR Code for root url' },
{ option: 'dirs', type: 'Boolean', description: 'show directory listing', default: 'true', },
{ option: 'cors', type: 'Boolean', description: 'send CORS headers', default: 'true', },
{ option: 'local', type: 'Boolean', description: 'local machine only', default: 'false', },
{ option: 'index', type: 'Boolean', description: 'serve index.html for directories', default: 'true', },
{ option: 'extensions', type: '[String]', description: 'extensions to try if path does not exist', default: '["html"]', },
{ option: 'unity-hack', type: 'Boolean', description: 'ignore .gz and .br when computing content type', default: 'true', },
{ option: 'shared-array-buffers', type: 'Boolean', description: "include headers 'Cross-Origin-Opener-Policy': 'same-origin' and 'Cross-Origin-Embedder-Policy': 'require-corp'", default: 'false', },
{ option: 'header', type: 'Object', description: 'extra headers to include eg --header=Content-Language:de-DE', mergeRepeatedObjects: true},
{ option: 'gzip', type: 'Boolean', description: 'serve .gz files if they exist', default: 'false', },
{ option: 'brotli', type: 'Boolean', description: 'serve .br files if they exist', default: 'false', },
{ option: 'robots', type: 'Boolean', description: 'serve a robots.txt if one does not exist', default: 'true', },
{ option: 'hidden', type: 'Boolean', description: 'show hidden dotfiles', default: 'false', },
{ option: 'username', type: 'String', description: 'username for basic auth' },
{ option: 'password', type: 'String', description: 'password for basic auth' },
{ option: 'ssl', alias: 'S', type: 'Boolean', description: 'enable https (will use fake cert if not specified)', },
{ option: 'cert', alias: 'C', type: 'String', description: 'Path to ssl cert file', },
{ option: 'key', alias: 'K', type: 'String', description: 'Path to ssl key file', },
],
prepend: `Usage: servez [options] [path-to-serve]`,
helpStyle: {
@@ -73,8 +93,13 @@ if (args.version) {
process.exit(0);
}

args.headers = args.header;
delete args.header;

const fs = require('fs');
const path = require('path');
const {QrCode, Ecc} = require('../lib/qrcodegen');
const hosts = [];

const root = path.resolve(args._[0] || process.cwd());
try {
@@ -96,11 +121,29 @@ process.stdin.destroy(); // this allows control-c to not print "Terminate Batch?
process.title = `servez ${root.split(/\\|\//g).slice(-3).join(path.sep)}`;

const commands = {
log(data) {
console.log(...data);
log(args) {
console.log(...args);
},
error(args) {
console.error(c.red(args.join(' ')));
},
host(args) {
const localRE = /\D0\.0\.0\.0.\D|\D127\.0\.0\.|\Wlocalhost\W/
const [data] = args;
const {root} = data;
if (!localRE.test(root)) {
hosts.push(root);
}
},
error(data) {
console.error(c.red([...data].join(' ')));
start(data) {
if (args.qr) {
for (const host of hosts) {
log.info(`--------------\nQR code for: ${host}`);
log.info(genQRCode(host));
log.info('');
}
}
log.info('press CTRL-C to stop the server.');
},
};

825 changes: 825 additions & 0 deletions lib/qrcodegen.js

Large diffs are not rendered by default.

227 changes: 122 additions & 105 deletions package-lock.json
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "servez",
"version": "1.11.0",
"version": "1.14.1",
"description": "A simple command line server to replace http-server",
"scripts": {
"start": "node ./bin/servez"
@@ -26,7 +26,7 @@
"ansi-colors": "^4.1.1",
"color-support": "^1.1.3",
"optionator": "^0.8.2",
"servez-lib": "^2.3.0"
"servez-lib": "^2.6.0"
},
"bin": {
"servez": "./bin/servez"
9 changes: 4 additions & 5 deletions src/server-worker.js
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ function sendCmd(cmd, data) {

c.enabled = useColors;
const logger = {
log: (...args) => sendCmd('log', [...args]),
error: (...args) => sendCmd('error', [...args]),
log: (...args) => sendCmd('log', args),
error: (...args) => sendCmd('error', args),
c,
};

@@ -29,8 +29,7 @@ const server = new Servez(Object.assign({
dataDir,
logger,
}, args));
server.on('start', () => {
logger.log('press CTRL-C to stop the server.');
});
server.on('host', (...args) => sendCmd('host', args));
server.on('start', (...args) => sendCmd('start', args));