Skip to content

Instantly share code, notes, and snippets.

@dibakarsutradhar
Last active August 17, 2018 15:01
Show Gist options
  • Save dibakarsutradhar/07e678a1b9c9e3199b0a4aa89253c2da to your computer and use it in GitHub Desktop.
Save dibakarsutradhar/07e678a1b9c9e3199b0a4aa89253c2da to your computer and use it in GitHub Desktop.
if(stats.isFile()) {
var mimeType = mimeTypes[path.extname(fileName).split(".").reverse()[0]];
res.writeHead(200, {'Content-type': mimeType});
var fileStream = fs.createReadStream(fileName);
fileStream.pipe(res);
} else if (stats.isDirectory()) {
res.writeHead(302, {
'Location': 'index.html'
});
res.end();
} else {
res.writeHead(500, {'Content-type': 'text/plain'});
res.write('500 Internal Error\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment