Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
req.params[0];
}
if (!fs.existsSync(filePath)) {
res.errorDetails = `File ${filePath} not found`;
return res.status(404).json({ err: res.errorDetails });
}
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
res.errorDetails = 'Forbidden: Directory Listing Denied';
return res.status(403).json({ err: res.errorDetails });
}
const fileStream = fs.createReadStream(filePath),
fileInfo = getFileInfo(filePath);
if (fileInfo.mimeType) {
res.set('Content-Type', fileInfo.mimeType);
}
if (fileInfo.gzip) {
res.set('Content-Encoding', 'gzip');
}
fileStream.on('open', () => {
fileStream.pipe(res);
});
};
};