node-static is sending .aspx extension content as download

496 views Asked by At

I'm not sure how to server .aspx files with node-static.

I am using node-static to serve .html .js .css, and images (works as expected), but when I request test.aspx (a file in the public folder) it prompts the browser(s) (Chrome and FF) to download as a file, when I want it to be treated as HTML (text/html).

node code is really basic

var node_static = require('node-static');
var node_static_file = new(node_static.Server)('./public');
var http = require('http');
var server = http.createServer(function(req, res) { 
    // static file server 
    req.addListener('end', function () {
        node_static_file.serve(req, res, function (err, result) {
            if (err) { // There was an error serving the file
                res.writeHead(err.status, err.headers);
                res.write("Error: Page " + err.message + " (" + err.status + ")");
                res.end();
            }
        });
    });
}).listen(80);

Thanks,

1

There are 1 answers

2
travis On BEST ANSWER

This is due to node-static not knowing what kind of file aspx is. Currently it looks like there is no default way to extend the mine types of node-static.

You can see in the code that if the mime type does not exist that Content-Type is set to application/octet-stream. A quick hack would to go into your node_modules directory and edit the lib/node-static/mime.js file and include a aspx extension and give it a content type of text/html.