Skip to content

Commit

Permalink
serve .wasm files as application/wasm (without charset) (#230)
Browse files Browse the repository at this point in the history
* serve .wasm files as application/wasm

* upgrade mime to 1.5.0 and remove temporary workaround from Shared.js
  • Loading branch information
rhmoller authored and shellscape committed Nov 22, 2017
1 parent 9ab1d96 commit 91506f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 6 additions & 1 deletion middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ module.exports = function(compiler, options) {
// server content
var content = context.fs.readFileSync(filename);
content = shared.handleRangeHeaders(content, req, res);
res.setHeader("Content-Type", mime.lookup(filename) + "; charset=UTF-8");
var contentType = mime.lookup(filename);
// do not add charset to WebAssembly files, otherwise compileStreaming will fail in the client
if(!/\.wasm$/.test(filename)) {
contentType += "; charset=UTF-8";
}
res.setHeader("Content-Type", contentType);
res.setHeader("Content-Length", content.length);
if(context.options.headers) {
for(var name in context.options.headers) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"memory-fs": "~0.4.1",
"mime": "^1.4.1",
"mime": "^1.5.0",
"path-is-absolute": "^1.0.0",
"range-parser": "^1.0.3",
"time-stamp": "^2.0.0"
Expand Down
22 changes: 22 additions & 0 deletions test/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@ describe("Server", function() {
});
});

describe("WebAssembly", function() {
before(function(done) {
app = express();
var compiler = webpack(webpackConfig);
var instance = middleware(compiler, {
stats: "errors-only",
quiet: true
});
app.use(instance);
listen = listenShorthand(done);
instance.fileSystem.writeFileSync("/hello.wasm", "welcome");
});
after(close);

it("request to hello.wasm", function(done) {
request(app).get("/hello.wasm")
.expect("welcome")
.expect("Content-Type", "application/wasm")
.expect(200, done);
});
});

describe("MultiCompiler", function() {
before(function(done) {
app = express();
Expand Down

0 comments on commit 91506f3

Please sign in to comment.