Send Content-Type headers with static files
Fixes a problem that occurs in Chrome 61 where the following error message appears in the console: 'Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.'
This commit is contained in:
parent
61879b175c
commit
99198cface
|
@ -18,6 +18,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ws": ">=0.4.27",
|
"ws": ">=0.4.27",
|
||||||
"optimist": "latest",
|
"optimist": "latest",
|
||||||
|
"mime-types" : "latest",
|
||||||
"policyfile": "latest"
|
"policyfile": "latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ var argv = require('optimist').argv,
|
||||||
url = require('url'),
|
url = require('url'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
|
mime = require('mime-types'),
|
||||||
|
|
||||||
Buffer = require('buffer').Buffer,
|
Buffer = require('buffer').Buffer,
|
||||||
WebSocketServer = require('ws').Server,
|
WebSocketServer = require('ws').Server,
|
||||||
|
@ -107,7 +108,13 @@ http_request = function (request, response) {
|
||||||
return http_error(response, 500, err);
|
return http_error(response, 500, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.writeHead(200);
|
var headers = {};
|
||||||
|
var contentType = mime.contentType(path.extname(filename));
|
||||||
|
if (contentType !== false) {
|
||||||
|
headers['Content-Type'] = contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.writeHead(200, headers);
|
||||||
response.write(file, "binary");
|
response.write(file, "binary");
|
||||||
response.end();
|
response.end();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue