Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加链接二维码 #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 24 additions & 3 deletions bin/anywhere
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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()
Expand All @@ -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);
}

Expand Down Expand Up @@ -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(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need setTimeout at here.

console.log("This is your QR code");
showQr(url)
},0)
}
});

var options = {
Expand All @@ -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
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down