File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ var colors = require('colors/safe'),
77 httpServer = require ( '../lib/http-server' ) ,
88 portfinder = require ( 'portfinder' ) ,
99 opener = require ( 'opener' ) ,
10- fs = require ( 'fs' ) ;
10+
11+ fs = require ( 'fs' ) ,
12+ url = require ( 'url' ) ;
1113var argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) , {
1214 alias : {
1315 tls : 'ssl'
@@ -160,6 +162,16 @@ function listen(port) {
160162 }
161163 }
162164
165+ if ( proxy ) {
166+ try {
167+ new url . URL ( proxy )
168+ }
169+ catch ( err ) {
170+ logger . info ( colors . red ( 'Error: Invalid proxy url' ) ) ;
171+ process . exit ( 1 ) ;
172+ }
173+ }
174+
163175 if ( tls ) {
164176 options . https = {
165177 cert : argv . C || argv . cert || 'cert.pem' ,
Original file line number Diff line number Diff line change @@ -101,3 +101,16 @@ test('setting mimeTypes via cli - directly', (t) => {
101101 } ) ;
102102 } ) ;
103103} ) ;
104+
105+ test ( '--proxy requires you to specify a protocol' , ( t ) => {
106+ t . plan ( 1 ) ;
107+
108+ const options = [ '.' , '--proxy' , 'google.com' ] ;
109+ const server = startServer ( options ) ;
110+
111+ tearDown ( server , t ) ;
112+
113+ server . on ( 'exit' , ( code ) => {
114+ t . equal ( code , 1 ) ;
115+ } ) ;
116+ } ) ;
You can’t perform that action at this time.
0 commit comments