Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function serveFile(path, stats) {
fs.readFile(path, function(err, contents) {
if(err) {
return serveError(path, err);
}
const responseData = formatter.formatFile(path, contents, stats);
// If we are supposed to serve this file or download, add headers
if(responseData.config.status === 200 && download) {
responseData.config.headers['Content-Disposition'] =
formatContentDisposition(path, stats);
}
resolve(new Response(responseData.body, responseData.config));
});
}