Last active
August 17, 2018 15:01
-
-
Save dibakarsutradhar/07e678a1b9c9e3199b0a4aa89253c2da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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