-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added QR Code for public IP #738
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
base: master
Are you sure you want to change the base?
Changes from all commits
0a35b4f
0a91929
a569197
b5a1c33
3983e59
e3bc05f
dea1508
af5e576
efcffcd
f5f25ef
49a56ad
d5af101
c1c5786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ | |
|
||
'use strict'; | ||
|
||
var colors = require('colors/safe'), | ||
os = require('os'), | ||
httpServer = require('../lib/http-server'), | ||
portfinder = require('portfinder'), | ||
opener = require('opener'), | ||
|
||
fs = require('fs'), | ||
url = require('url'); | ||
var colors = require('colors/safe'), | ||
os = require('os'), | ||
httpServer = require('../lib/http-server'), | ||
portfinder = require('portfinder'), | ||
opener = require('opener'), | ||
fs = require('fs'), | ||
qrcode = require('qrcode-terminal'), | ||
url = require('url'); | ||
var argv = require('minimist')(process.argv.slice(2), { | ||
alias: { | ||
tls: 'ssl' | ||
|
@@ -18,7 +18,6 @@ var argv = require('minimist')(process.argv.slice(2), { | |
var ifaces = os.networkInterfaces(); | ||
|
||
process.title = 'http-server'; | ||
|
||
if (argv.h || argv.help) { | ||
console.log([ | ||
'usage: http-server [path] [options]', | ||
|
@@ -52,9 +51,10 @@ if (argv.h || argv.help) { | |
' --password Password for basic authentication [none]', | ||
' Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD', | ||
'', | ||
' -S --tls --ssl Enable secure request serving with TLS/SSL (HTTPS)', | ||
' -C --cert Path to TLS cert file (default: cert.pem)', | ||
' -K --key Path to TLS key file (default: key.pem)', | ||
' -S --ssl Enable https.', | ||
' -C --cert Path to ssl cert file (default: cert.pem).', | ||
' -K --key Path to ssl key file (default: key.pem).', | ||
' --qr-code (Experimental) Show QR code for public IP', | ||
'', | ||
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]', | ||
' --no-dotfiles Do not show dotfiles', | ||
|
@@ -94,8 +94,8 @@ if (!argv.s && !argv.silent) { | |
request: function (req, res, error) { | ||
var date = utc ? new Date().toUTCString() : new Date(); | ||
var ip = argv['log-ip'] | ||
? req.headers['x-forwarded-for'] || '' + req.connection.remoteAddress | ||
: ''; | ||
? req.headers['x-forwarded-for'] || '' + req.connection.remoteAddress | ||
: ''; | ||
if (error) { | ||
logger.info( | ||
'[%s] %s "%s %s" Error (%s): "%s"', | ||
|
@@ -115,8 +115,8 @@ if (!argv.s && !argv.silent) { | |
} | ||
else if (colors) { | ||
logger = { | ||
info: function () {}, | ||
request: function () {} | ||
info: function () { }, | ||
request: function () { } | ||
}; | ||
} | ||
|
||
|
@@ -153,7 +153,8 @@ function listen(port) { | |
showDotfiles: argv.dotfiles, | ||
mimetypes: argv.mimetypes, | ||
username: argv.username || process.env.NODE_HTTP_SERVER_USERNAME, | ||
password: argv.password || process.env.NODE_HTTP_SERVER_PASSWORD | ||
password: argv.password || process.env.NODE_HTTP_SERVER_PASSWORD, | ||
showQR: argv['qr-code'] | ||
}; | ||
|
||
if (argv.cors) { | ||
|
@@ -198,6 +199,7 @@ function listen(port) { | |
var server = httpServer.createServer(options); | ||
server.listen(port, host, function () { | ||
var protocol = tls ? 'https://' : 'http://'; | ||
var plainIp = protocol + host; | ||
|
||
logger.info([ | ||
colors.yellow('Starting up http-server, serving '), | ||
|
@@ -227,6 +229,7 @@ function listen(port) { | |
Object.keys(ifaces).forEach(function (dev) { | ||
ifaces[dev].forEach(function (details) { | ||
if (details.family === 'IPv4') { | ||
plainIp = protocol + details.address + ':' + port.toString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized, this is inside a loop! So it'll only be making a code for the last IP, which is usually the public IP, but I don't believe that's guaranteed. Some thoughts, and I welcome yours:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am out of ideas right now. But I like the one's you proposed I'm all onboard with either. We can use device identifier (like Or maybe the other one where we can print IP next to QR. But I have some concerns with this one as this won't give an option for local IP and if we try to make QR for all IPs that will fill up the screen quickly. Personally I like the info as clean as it was with addition of QR optionally. What are your suggestions? |
||
logger.info((' ' + protocol + details.address + ':' + colors.green(port.toString()))); | ||
} | ||
}); | ||
|
@@ -241,7 +244,12 @@ function listen(port) { | |
logger.info('Unhandled requests will be served from: ' + proxy); | ||
} | ||
} | ||
|
||
if (options.showQR) { | ||
logger.info(colors.yellow("\nWARNING: ") + "The QR Code is an experimental feature and is not guaranteed to work properly in all terminals or fonts.") | ||
qrcode.generate(plainIp, { small: true }, function (qr) { | ||
console.log(qr); | ||
}) | ||
} | ||
logger.info('Hit CTRL-C to stop the server'); | ||
if (argv.o) { | ||
const openHost = host === '0.0.0.0' ? '127.0.0.1' : host; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.