Skip to content

Commit 91506f3

Browse files
rhmollershellscape
authored andcommitted
serve .wasm files as application/wasm (without charset) (#230)
* serve .wasm files as application/wasm * upgrade mime to 1.5.0 and remove temporary workaround from Shared.js
1 parent 9ab1d96 commit 91506f3

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

middleware.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ module.exports = function(compiler, options) {
6969
// server content
7070
var content = context.fs.readFileSync(filename);
7171
content = shared.handleRangeHeaders(content, req, res);
72-
res.setHeader("Content-Type", mime.lookup(filename) + "; charset=UTF-8");
72+
var contentType = mime.lookup(filename);
73+
// do not add charset to WebAssembly files, otherwise compileStreaming will fail in the client
74+
if(!/\.wasm$/.test(filename)) {
75+
contentType += "; charset=UTF-8";
76+
}
77+
res.setHeader("Content-Type", contentType);
7378
res.setHeader("Content-Length", content.length);
7479
if(context.options.headers) {
7580
for(var name in context.options.headers) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"memory-fs": "~0.4.1",
11-
"mime": "^1.4.1",
11+
"mime": "^1.5.0",
1212
"path-is-absolute": "^1.0.0",
1313
"range-parser": "^1.0.3",
1414
"time-stamp": "^2.0.0"

test/Server.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@ describe("Server", function() {
190190
});
191191
});
192192

193+
describe("WebAssembly", function() {
194+
before(function(done) {
195+
app = express();
196+
var compiler = webpack(webpackConfig);
197+
var instance = middleware(compiler, {
198+
stats: "errors-only",
199+
quiet: true
200+
});
201+
app.use(instance);
202+
listen = listenShorthand(done);
203+
instance.fileSystem.writeFileSync("/hello.wasm", "welcome");
204+
});
205+
after(close);
206+
207+
it("request to hello.wasm", function(done) {
208+
request(app).get("/hello.wasm")
209+
.expect("welcome")
210+
.expect("Content-Type", "application/wasm")
211+
.expect(200, done);
212+
});
213+
});
214+
193215
describe("MultiCompiler", function() {
194216
before(function(done) {
195217
app = express();

0 commit comments

Comments
 (0)