From 35ac32fe4909c9bc0849c6f6a69db8f3be72c203 Mon Sep 17 00:00:00 2001 From: Kamil Tunkiewicz Date: Fri, 16 Oct 2020 19:24:30 +0200 Subject: [PATCH] serving any type of file --- cli/index.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cli/index.ts b/cli/index.ts index be84c418..f3e18a55 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -204,20 +204,14 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) { } else { if (options.static && options.static !== '' && request.url?.startsWith('/' + options.static)) { const filePath = join(dirname(pathToSpec), request.url); - const fileExists = existsSync(filePath); - if (fileExists) { - - respondWithGzip( - createReadStream(filePath, 'utf8'), - request, - response, - { - 'Content-Type': lookup(filePath), - }, - ); - } else { + const file = createReadStream(filePath); + file.on('open', function () { + response.setHeader('Content-Type', lookup(filePath) || 'text/plain'); + file.pipe(response); + }); + file.on('error', function () { fileNotFound(); - } + }); } else { fileNotFound(); }