Simple: you're setting the Content-Type
header to text/html
, always. Also, it will always serve your index.html file. Look:
fs.readFile('index.html', function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"}); // <-- HERE!
response.write(html); // <-- HERE!
response.end();
}).listen(1337, '127.0.0.1');
});
You should parse the URL, look up what file you want to require, read its contents and write them to the response if it exists, otherwise serve an 404 error. Also, you'll need to set the correct headers.
So, do you still want to do it at your own?
At least, try something like send, which is a basic static file server.