11#!/usr/bin/env node
22
33'use strict' ;
4-
54var chalk = require ( 'chalk' ) ,
65 os = require ( 'os' ) ,
76 httpServer = require ( '../lib/http-server' ) ,
@@ -53,9 +52,9 @@ if (argv.h || argv.help) {
5352 ' --password Password for basic authentication [none]' ,
5453 ' Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD' ,
5554 '' ,
56- ' -S --tls --ssl Enable secure request serving with TLS/SSL (HTTPS)' ,
57- ' -C --cert Path to TLS cert file (default: cert.pem)' ,
58- ' -K --key Path to TLS key file (default: key.pem)' ,
55+ ' -S --tls --ssl Enable secure request serving with TLS/SSL (HTTPS)' ,
56+ ' -C --cert Path to TLS cert file (default: cert.pem)' ,
57+ ' -K --key Path to TLS key file (default: key.pem)' ,
5958 '' ,
6059 ' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]' ,
6160 ' --no-dotfiles Do not show dotfiles' ,
@@ -74,7 +73,7 @@ var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
7473 proxyOptions = argv [ 'proxy-options' ] ,
7574 utc = argv . U || argv . utc ,
7675 version = argv . v || argv . version ,
77- redirect = ! ! argv . R || ! ! argv [ 'https-redirect' ] ,
76+ redirect = ! ! argv . R || ! ! argv [ 'https-redirect' ] ,
7877 logger ;
7978
8079var proxyOptionsBooleanProps = [
@@ -128,40 +127,40 @@ if (version) {
128127}
129128
130129if ( port === true ) {
131- logger . info ( colors . red ( 'Error: --port needs a value' ) ) ;
130+ logger . info ( chalk . red ( 'Error: --port needs a value' ) ) ;
132131 process . exit ( 1 ) ;
133132 return ;
134133}
135134
136- if ( ssl && redirect ) {
135+ if ( tls && redirect ) {
137136 var ports = [ ] ;
138137 if ( ! port ) {
139138 ports = [ 8080 , 443 ] ;
140139 }
141140 else if ( typeof port === 'string' ) {
142- ports = ( port . toString ( ) || '' ) . split ( ',' ) . map ( function ( s ) { parseInt ( s , 10 ) } ) ;
141+ ports = ( port . toString ( ) || '' ) . split ( ',' ) . map ( function ( s ) { return parseInt ( s , 10 ) } ) ;
143142 }
144143 else {
145- logger . info ( colors . red ( 'Error: Cannot parse "--port ' + port + '" of type ' + typeof port + '. Port has to be in the format [httpPort,httpsPort]\nExample: --port 8080,443' ) ) ;
144+ logger . info ( chalk . red ( 'Error: Cannot parse "--port ' + port + '" of type ' + typeof port + '. Port has to be in the format [httpPort,httpsPort]\nExample: --port 8080,443' ) ) ;
146145 process . exit ( 1 ) ;
147146 }
148147
149148 if ( ports . length === 2 ) {
150- if ( isNaN ( ports [ 0 ] ) || isNaN ( ports [ 1 ] ) ) {
151- logger . info ( colors . red ( 'Error parsing "--port ' + port + '". [' + ports + '] is not of type [number,number]' ) ) ;
149+ if ( isNaN ( ports [ 0 ] ) || isNaN ( ports [ 1 ] ) ) {
150+ logger . info ( chalk . red ( 'Error parsing "--port ' + port + '". [' + ports + '] is not of type [number,number]' ) ) ;
152151 process . exit ( 1 ) ;
153152 }
154153 }
155154 else {
156- logger . info ( colors . red ( 'Error: Cannot parse "--port ' + port + '"\nExample: --port 8080,443' ) ) ;
155+ logger . info ( chalk . red ( 'Error: Cannot parse "--port ' + port + '"\nExample: --port 8080,443' ) ) ;
157156 process . exit ( 1 ) ;
158157 }
159158
160159 listen ( ports [ 1 ] ) ;
161160 listen ( ports [ 0 ] , ports [ 1 ] ) ;
162161}
163- else if ( ! ssl && redirect ) {
164- logger . info ( colors . red ( 'Error: Can\'t redirect to https when the main server runs on http!' ) ) ;
162+ else if ( ! tls && redirect ) {
163+ logger . info ( chalk . red ( 'Error: Can\'t redirect to https when the main server runs on http!' ) ) ;
165164}
166165else {
167166 if ( ! port ) {
@@ -197,7 +196,7 @@ function listen(port, redirectPort) {
197196 password : argv . password || process . env . NODE_HTTP_SERVER_PASSWORD
198197 } ;
199198
200- var isSSLServer = ( ssl && ! redirectPort ) ;
199+ var isTLSServer = ( tls && ! redirectPort ) ;
201200
202201 if ( argv . cors ) {
203202 options . cors = true ;
@@ -216,7 +215,7 @@ function listen(port, redirectPort) {
216215 }
217216 }
218217
219- if ( isSSLServer ) {
218+ if ( isTLSServer ) {
220219 options . https = {
221220 cert : argv . C || argv . cert || 'cert.pem' ,
222221 key : argv . K || argv . key || 'key.pem' ,
@@ -241,13 +240,13 @@ function listen(port, redirectPort) {
241240 var server = httpServer . createServer ( options ) ;
242241 server . listen ( port , host , function ( ) {
243242
244- var protocol = isSSLServer ? 'https://' : 'http://' ;
243+ var protocol = isTLSServer ? 'https://' : 'http://' ;
245244
246245 logger . info ( [
247- colors . yellow ( 'Starting up http-server, serving ' ) ,
248- colors . cyan ( server . root ) ,
249- isSSLServer ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : '' ,
250- colors . yellow ( '\nAvailable on:' )
246+ chalk . yellow ( 'Starting up http-server, serving ' ) ,
247+ chalk . cyan ( server . root ) ,
248+ isTLSServer ? ( chalk . yellow ( ' through' ) + chalk . cyan ( ' https' ) ) : '' ,
249+ chalk . yellow ( '\nAvailable on:' )
251250 ] . join ( '' ) ) ;
252251
253252 logger . info ( [ chalk . yellow ( '\nhttp-server version: ' ) , chalk . cyan ( require ( '../package.json' ) . version ) ] . join ( '' ) ) ;
0 commit comments