I'm writing a combiner module for node js. I'm using express to get the files like the following:
app.get('/combine/js/?files=scripts/file1.js;scripts/file2.js', function(req, res){
res.contentType('text/javascript');
res.end(content); //the combined files content
});
Now, when the page is loaded I'm getting the following error in chrome: 'Resource interpreted as Script but transferred with MIME type application/octet-stream'
What am I doing wrong?
UPDATE: this is the full app.get combiner function that response the content...
app.get('/combiner/:type/?', function(req, res){
var type = req.params.type;
var files = [];
files = req.query.files.split(';');
var content = combiner.combine(type, files);
switch(type){
case 'js': res.contentType('text/javascript'); break;
case 'css': res.contentType('text/css'); break;
}
content = content.replace('<:=appid=:>', vars.appid);
res.end(content);
});
From what I can see, it looks like the Express docs might be wrong here. They clearly say that giving the mime type will work, but that isn't happening for you, or me in my tests.
You should either set the content-type automatically:
res.header('Content-Type', 'application/javascript');
or pass the file extension to res.contentType()
.
res.contentType('js');