mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 21:54:53 +03:00
serving any type of file
This commit is contained in:
parent
9a5a4774d4
commit
35ac32fe49
20
cli/index.ts
20
cli/index.ts
|
@ -204,20 +204,14 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
||||||
} else {
|
} else {
|
||||||
if (options.static && options.static !== '' && request.url?.startsWith('/' + options.static)) {
|
if (options.static && options.static !== '' && request.url?.startsWith('/' + options.static)) {
|
||||||
const filePath = join(dirname(pathToSpec), request.url);
|
const filePath = join(dirname(pathToSpec), request.url);
|
||||||
const fileExists = existsSync(filePath);
|
const file = createReadStream(filePath);
|
||||||
if (fileExists) {
|
file.on('open', function () {
|
||||||
|
response.setHeader('Content-Type', lookup(filePath) || 'text/plain');
|
||||||
respondWithGzip(
|
file.pipe(response);
|
||||||
createReadStream(filePath, 'utf8'),
|
});
|
||||||
request,
|
file.on('error', function () {
|
||||||
response,
|
|
||||||
{
|
|
||||||
'Content-Type': lookup(filePath),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
fileNotFound();
|
fileNotFound();
|
||||||
}
|
});
|
||||||
} else {
|
} else {
|
||||||
fileNotFound();
|
fileNotFound();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user