diff --git a/README.md b/README.md index 5131fe7..a5df7de 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ $ anywhere -h localhost -p 8888 $ anywhere -d ~/git/anywhere // or enable html5 history $ anywhere -f /index.html +// or with QRcode and silent +$ anywhere -q +// or with https QRcode and silent +$ anywhere -e ``` ## Help @@ -40,6 +44,8 @@ Usage: anywhere -h localhost // localhost as hostname anywhere -d /home // /home as root anywhere -f /index.html // Enable html5 history,the index is /index.html + anywhere -q // show QRcode + anywhere -e // show QRcode with https ``` ## Visit diff --git a/bin/anywhere b/bin/anywhere index 94efacd..f0ee8ea 100755 --- a/bin/anywhere +++ b/bin/anywhere @@ -10,6 +10,7 @@ var connect = require('connect'); var serveStatic = require('serve-static'); var serveIndex = require('serve-index'); var fallback = require('connect-history-api-fallback'); +var qrcode = require('qrcode-terminal') var debug = require('debug'); debug.enable('anywhere'); @@ -23,10 +24,12 @@ var argv = require("minimist")(process.argv.slice(2), { 'hostname': 'h', 'dir': 'd', 'log': 'l', - 'fallback': 'f' + 'fallback': 'f', + 'QRcode': 'q', + 'QRcodeHttps': 'e' }, string: ['port', 'hostname', 'fallback'], - boolean: ['silent', 'log'], + boolean: ['silent', 'log', 'QRcode', 'QRcodeHttps'], 'default': { 'port': 8000, 'dir': process.cwd() @@ -44,6 +47,8 @@ if (argv.help) { console.log(" anywhere -d /home // /home as root"); console.log(" anywhere -l // print log"); console.log(" anywhere -f // Enable history fallback"); + console.log(" anywhere -q // show QRcode"); + console.log(" anywhere -e // show QRcode with https"); process.exit(0); } @@ -118,9 +123,15 @@ http.createServer(app).listen(port, function () { port = (port != 80 ? ':' + port : ''); var url = "http://" + hostname + port + '/'; console.log("Running at " + url); - if (!argv.silent) { + if (!argv.silent && !argv.QRcode && !argv.QRcodeHttps) { openURL(url); } + if (!!argv.QRcode) { + setTimeout(function(){ + console.log("This is your QR code"); + showQr(url) + },0) + } }); var options = { @@ -132,4 +143,14 @@ https.createServer(options, app).listen(secure, function () { secure = (secure != 80 ? ':' + secure : ''); var url = "https://" + hostname + secure + '/'; console.log("Also running at " + url); + if (!!argv.QRcodeHttps) { + console.log("This is your QR code with https link"); + showQr(url) + } }); + +var showQr = function(url) { + qrcode.generate(url, { + small: true + }); +} \ No newline at end of file diff --git a/package.json b/package.json index f18dd89..6870abe 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "connect-history-api-fallback": "^1.2.0", "debug": "^2.2.0", "minimist": "^1.2.0", + "qrcode-terminal": "^0.12.0", "serve-index": "^1.9.1", "serve-static": "^1.13.2" },