22
33'use strict' ;
44
5- var colors = require ( 'colors/safe' ) ,
6- os = require ( 'os' ) ,
7- httpServer = require ( '../lib/http-server' ) ,
8- portfinder = require ( 'portfinder' ) ,
9- opener = require ( 'opener' ) ,
10- fs = require ( 'fs' ) ,
11- argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
5+ var colors = require ( 'colors/safe' ) ,
6+ os = require ( 'os' ) ,
7+ httpServer = require ( '../lib/http-server' ) ,
8+ portfinder = require ( 'portfinder' ) ,
9+ opener = require ( 'opener' ) ,
10+ fs = require ( 'fs' ) ,
11+ argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ,
12+ QRCode = require ( 'qrcode' ) ;
1213var ifaces = os . networkInterfaces ( ) ;
14+ var plainIp ;
1315
1416process . title = 'http-server' ;
1517
@@ -59,21 +61,21 @@ if (argv.h || argv.help) {
5961}
6062
6163var port = argv . p || argv . port || parseInt ( process . env . PORT , 10 ) ,
62- host = argv . a || '0.0.0.0' ,
63- ssl = argv . S || argv . ssl ,
64- proxy = argv . P || argv . proxy ,
65- utc = argv . U || argv . utc ,
66- version = argv . v || argv . version ,
67- logger ;
64+ host = argv . a || '0.0.0.0' ,
65+ ssl = argv . S || argv . ssl ,
66+ proxy = argv . P || argv . proxy ,
67+ utc = argv . U || argv . utc ,
68+ version = argv . v || argv . version ,
69+ logger ;
6870
6971if ( ! argv . s && ! argv . silent ) {
7072 logger = {
7173 info : console . log ,
7274 request : function ( req , res , error ) {
7375 var date = utc ? new Date ( ) . toUTCString ( ) : new Date ( ) ;
7476 var ip = argv [ 'log-ip' ]
75- ? req . headers [ 'x-forwarded-for' ] || '' + req . connection . remoteAddress
76- : '' ;
77+ ? req . headers [ 'x-forwarded-for' ] || '' + req . connection . remoteAddress
78+ : '' ;
7779 if ( error ) {
7880 logger . info (
7981 '[%s] %s "%s %s" Error (%s): "%s"' ,
@@ -93,8 +95,8 @@ if (!argv.s && !argv.silent) {
9395}
9496else if ( colors ) {
9597 logger = {
96- info : function ( ) { } ,
97- request : function ( ) { }
98+ info : function ( ) { } ,
99+ request : function ( ) { }
98100 } ;
99101}
100102
@@ -166,21 +168,21 @@ function listen(port) {
166168 var protocol = ssl ? 'https://' : 'http://' ;
167169
168170 logger . info ( [ colors . yellow ( 'Starting up http-server, serving ' ) ,
169- colors . cyan ( server . root ) ,
170- ssl ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
171+ colors . cyan ( server . root ) ,
172+ ssl ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
171173 ] . join ( '' ) ) ;
172174
173175 logger . info ( [ colors . yellow ( '\nhttp-server version: ' ) , colors . cyan ( require ( '../package.json' ) . version ) ] . join ( '' ) ) ;
174176
175177 logger . info ( [ colors . yellow ( '\nhttp-server settings: ' ) ,
176- ( [ colors . yellow ( 'CORS: ' ) , argv . cors ? colors . cyan ( argv . cors ) : colors . red ( 'disabled' ) ] . join ( '' ) ) ,
177- ( [ colors . yellow ( 'Cache: ' ) , argv . c ? ( argv . c === '-1' ? colors . red ( 'disabled' ) : colors . cyan ( argv . c + ' seconds' ) ) : colors . cyan ( '3600 seconds' ) ] . join ( '' ) ) ,
178- ( [ colors . yellow ( 'Connection Timeout: ' ) , argv . t === '0' ? colors . red ( 'disabled' ) : ( argv . t ? colors . cyan ( argv . t + ' seconds' ) : colors . cyan ( '120 seconds' ) ) ] . join ( '' ) ) ,
179- ( [ colors . yellow ( 'Directory Listings: ' ) , argv . d ? colors . red ( 'not visible' ) : colors . cyan ( 'visible' ) ] . join ( '' ) ) ,
180- ( [ colors . yellow ( 'AutoIndex: ' ) , argv . i ? colors . red ( 'not visible' ) : colors . cyan ( 'visible' ) ] . join ( '' ) ) ,
181- ( [ colors . yellow ( 'Serve GZIP Files: ' ) , argv . g || argv . gzip ? colors . cyan ( 'true' ) : colors . red ( 'false' ) ] . join ( '' ) ) ,
182- ( [ colors . yellow ( 'Serve Brotli Files: ' ) , argv . b || argv . brotli ? colors . cyan ( 'true' ) : colors . red ( 'false' ) ] . join ( '' ) ) ,
183- ( [ colors . yellow ( 'Default File Extension: ' ) , argv . e ? colors . cyan ( argv . e ) : ( argv . ext ? colors . cyan ( argv . ext ) : colors . red ( 'none' ) ) ] . join ( '' ) )
178+ ( [ colors . yellow ( 'CORS: ' ) , argv . cors ? colors . cyan ( argv . cors ) : colors . red ( 'disabled' ) ] . join ( '' ) ) ,
179+ ( [ colors . yellow ( 'Cache: ' ) , argv . c ? ( argv . c === '-1' ? colors . red ( 'disabled' ) : colors . cyan ( argv . c + ' seconds' ) ) : colors . cyan ( '3600 seconds' ) ] . join ( '' ) ) ,
180+ ( [ colors . yellow ( 'Connection Timeout: ' ) , argv . t === '0' ? colors . red ( 'disabled' ) : ( argv . t ? colors . cyan ( argv . t + ' seconds' ) : colors . cyan ( '120 seconds' ) ) ] . join ( '' ) ) ,
181+ ( [ colors . yellow ( 'Directory Listings: ' ) , argv . d ? colors . red ( 'not visible' ) : colors . cyan ( 'visible' ) ] . join ( '' ) ) ,
182+ ( [ colors . yellow ( 'AutoIndex: ' ) , argv . i ? colors . red ( 'not visible' ) : colors . cyan ( 'visible' ) ] . join ( '' ) ) ,
183+ ( [ colors . yellow ( 'Serve GZIP Files: ' ) , argv . g || argv . gzip ? colors . cyan ( 'true' ) : colors . red ( 'false' ) ] . join ( '' ) ) ,
184+ ( [ colors . yellow ( 'Serve Brotli Files: ' ) , argv . b || argv . brotli ? colors . cyan ( 'true' ) : colors . red ( 'false' ) ] . join ( '' ) ) ,
185+ ( [ colors . yellow ( 'Default File Extension: ' ) , argv . e ? colors . cyan ( argv . e ) : ( argv . ext ? colors . cyan ( argv . ext ) : colors . red ( 'none' ) ) ] . join ( '' ) )
184186 ] . join ( '\n' ) ) ;
185187
186188 logger . info ( colors . yellow ( '\nAvailable on:' ) ) ;
@@ -191,6 +193,7 @@ function listen(port) {
191193 Object . keys ( ifaces ) . forEach ( function ( dev ) {
192194 ifaces [ dev ] . forEach ( function ( details ) {
193195 if ( details . family === 'IPv4' ) {
196+ plainIp = protocol + details . address + ':' + port . toString ( )
194197 logger . info ( ( ' ' + protocol + details . address + ':' + colors . green ( port . toString ( ) ) ) ) ;
195198 }
196199 } ) ;
@@ -200,7 +203,9 @@ function listen(port) {
200203 if ( typeof proxy === 'string' ) {
201204 logger . info ( 'Unhandled requests will be served from: ' + proxy ) ;
202205 }
203-
206+ QRCode . toString ( plainIp , { type : 'terminal' } , function ( err , qr ) {
207+ console . log ( qr ) ;
208+ } )
204209 logger . info ( 'Hit CTRL-C to stop the server' ) ;
205210 if ( argv . o ) {
206211 const openHost = host === '0.0.0.0' ? '127.0.0.1' : host ;
0 commit comments