serving any type of file

This commit is contained in:
Kamil Tunkiewicz 2020-10-16 19:24:30 +02:00
parent 9a5a4774d4
commit 35ac32fe49

View File

@ -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();
}