@@ -7,13 +7,14 @@ import https from 'node:https';
77import zlib from 'node:zlib' ;
88import { promisify } from 'node:util' ;
99import httpProxy from 'http-proxy' ;
10+ import process from "node:process" ;
1011
1112const gzip = promisify ( zlib . gzip ) ;
1213
13- import mimeTypes from './utils/mimeTypes' ;
14- import directoryListing from './utils/directoryListing' ;
14+ import mimeTypes from './utils/mimeTypes.ts ' ;
15+ import directoryListing from './utils/directoryListing.ts ' ;
1516
16- import { fileWatch , usePort , networkIps } from './utils/common' ;
17+ import { fileWatch , usePort , networkIps } from './utils/common.ts ' ;
1718import { existsSync } from 'node:fs' ;
1819import Server from 'http-proxy' ;
1920
@@ -108,9 +109,6 @@ export const servor = async ({
108109 const isRouteRequest = ( pathname : string ) => ! ~ pathname . split ( '/' ) . pop ( ) ! . indexOf ( '.' ) ;
109110 const isDir = async ( pathname : string ) =>
110111 existsSync ( pathname . split ( '/' ) . pop ( ) ! ) && ( await fs . lstat ( pathname . split ( '/' ) . pop ( ) ! ) ) . isDirectory ( ) ;
111- const utf8 = ( file : WithImplicitCoercion < string > | { [ Symbol . toPrimitive ] ( hint : 'string' ) : string } ) =>
112- Buffer . from ( file , 'binary' ) . toString ( 'utf8' ) ;
113-
114112 const baseDoc = ( pathname = '' , base = path . join ( '/' , pathname , '/' ) ) =>
115113 `<!doctype html><meta charset="utf-8"/><base href="${ base } "/>` ;
116114
@@ -123,7 +121,7 @@ export const servor = async ({
123121 const _sendFile = (
124122 res : http2 . Http2ServerResponse ,
125123 status : number ,
126- file : any ,
124+ file : string | Uint8Array ,
127125 ext : string ,
128126 encoding : BufferEncoding
129127 ) => {
@@ -132,10 +130,10 @@ export const servor = async ({
132130 res . end ( ) ;
133131 } ;
134132
135- const sendFile = async ( res : http2 . Http2ServerResponse , status : number , file : any , ext : string ) => {
136- if ( [ 'js' , 'css' , 'html' , 'json' , 'xml' , 'svg' ] . includes ( ext ) ) {
133+ const sendFile = async ( res : http2 . Http2ServerResponse , status : number , file : string | Uint8Array , ext : string ) => {
134+ if ( [ 'js' , 'css' , 'html' , 'json' , 'xml' , 'svg' ] . includes ( ext ) ) {
137135 res . setHeader ( 'content-encoding' , 'gzip' ) ;
138- const content = await gzip ( utf8 ( file ) ) ;
136+ const content = await gzip ( file ) ;
139137 _sendFile ( res , status , content , ext , 'utf-8' ) ;
140138 } else {
141139 _sendFile ( res , status , file , ext , 'binary' ) ;
@@ -174,7 +172,8 @@ export const servor = async ({
174172 } else {
175173 await sendFile ( res , 200 , file , ext ) ;
176174 }
177- } catch {
175+ } catch ( err ) {
176+ console . error ( err ) ;
178177 return sendError ( res , 500 ) ;
179178 }
180179 } ;
@@ -201,7 +200,8 @@ export const servor = async ({
201200 return await sendFile ( res , status , baseDoc ( pathname ) + file , 'html' ) ;
202201 }
203202 return await sendFile ( res , status , file + inject + livereload , 'html' ) ;
204- } catch {
203+ } catch ( err ) {
204+ console . error ( err ) ;
205205 return sendError ( res , 500 ) ;
206206 }
207207 } ;
0 commit comments