@@ -21,6 +21,13 @@ if (!args) { // cliBasics handled
2121
2222const dir = args . directory || '.' ;
2323
24+ /**
25+ * @param {http.IncomingMessage } request
26+ * @param {http.ServerResponse<http.IncomingMessage> & {
27+ * req: http.IncomingMessage;
28+ * }} response
29+ * @param {number } [statusCode]
30+ */
2431const log = function ( request , response , statusCode ) {
2532 const d = new Date ( ) ;
2633 /* c8 ignore next 3 -- Time-dependent */
@@ -31,10 +38,12 @@ const log = function(request, response, statusCode) {
3138
3239 line = datestr + ' [' + response . statusCode + ']: ' + request . url ;
3340 let colorized = line ;
34- /* c8 ignore next 5 -- Environment */
41+ /* c8 ignore next 7 -- Environment */
3542 if ( tty . isatty ( process . stdout . fd ) ) {
36- colorized = ( response . statusCode >= 500 ) ? colors . red . bold ( line ) :
37- ( response . statusCode >= 400 ) ? colors . red ( line ) :
43+ colorized = ( response . statusCode >= 500 )
44+ // @ts -expect-error TS error
45+ ? colors . red . bold ( line )
46+ : ( response . statusCode >= 400 ) ? colors . red ( line ) :
3847 line ;
3948 }
4049 console . log ( colorized ) ;
@@ -51,7 +60,10 @@ if (args['headers']) {
5160}
5261
5362if ( args [ 'header-file' ] ) {
54- options . headers = JSON . parse ( fs . readFileSync ( args [ 'header-file' ] ) ) ;
63+ options . headers = JSON . parse (
64+ // @ts -expect-error Works fine
65+ fs . readFileSync ( args [ 'header-file' ] )
66+ ) ;
5567}
5668
5769if ( args [ 'gzip' ] ) {
@@ -66,6 +78,10 @@ const file = new(statik.Server)(dir, options);
6678
6779const server = http . createServer ( function ( request , response ) {
6880 request . addListener ( 'end' , function ( ) {
81+ /**
82+ * @param {null|import('../lib/node-static.js').ResultInfo } e
83+ * @param {import('../lib/node-static.js').ResultInfo } [rsp]
84+ */
6985 const callback = function ( e , rsp ) {
7086 if ( e && e . status === 404 ) {
7187 response . writeHead ( e . status , e . headers ) ;
@@ -76,6 +92,11 @@ const server = http.createServer(function (request, response) {
7692 }
7793 } ;
7894
95+ /* c8 ignore next 3 -- TS guard */
96+ if ( typeof request . url !== 'string' ) {
97+ return ;
98+ }
99+
79100 // Parsing catches:
80101 // npm start -- --spa --index-file test/fixtures/there/index.html
81102 // with http://127.0.0.1:8080/test/fixtures/there?email=john.cena
0 commit comments