I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same
example.com
index.html
Rather than dealing with a switch statement, I think it's neater to lookup the content type from a dictionary:
var contentTypesByExtension = { 'html': "text/html", 'js': "text/javascript" }; ... var contentType = contentTypesByExtension[fileExtension] || 'text/plain';