diff --git a/lib/middleware.js b/lib/middleware.js index 5054898e3..2afa2588f 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -5,6 +5,10 @@ const mime = require('mime'); const DevMiddlewareError = require('./DevMiddlewareError'); const { getFilenameFromUrl, handleRangeHeaders, handleRequest, ready } = require('./util'); +// Do not add a charset to the Content-Type header of these file types +// otherwise the client will fail to render them correctly. +const NonCharsetFileTypes = /\.(wasm|usdz)$/; + module.exports = function wrapper(context) { return function middleware(req, res, next) { // fixes #282. credit @cexoso. in certain edge situations res.locals is @@ -71,8 +75,7 @@ module.exports = function wrapper(context) { let contentType = mime.getType(filename) || ''; - // do not add charset to WebAssembly files, otherwise compileStreaming will fail in the client - if (!/\.wasm$/.test(filename)) { + if (!NonCharsetFileTypes.test(filename)) { contentType += '; charset=UTF-8'; } diff --git a/test/tests/server.js b/test/tests/server.js index 5a94344ab..90f9e6565 100644 --- a/test/tests/server.js +++ b/test/tests/server.js @@ -312,17 +312,21 @@ describe('Server', () => { }); }); - describe('WebAssembly', () => { + describe('Special file type headers', () => { before((done) => { app = express(); const compiler = webpack(webpackConfig); instance = middleware(compiler, { stats: 'errors-only', - logLevel + logLevel, + mimeTypes: { + 'model/vnd.pixar.usd': ['usdz'] + } }); app.use(instance); listen = listenShorthand(done); instance.fileSystem.writeFileSync('/hello.wasm', 'welcome'); + instance.fileSystem.writeFileSync('/3dAr.usdz', '010101'); }); after(close); @@ -332,6 +336,13 @@ describe('Server', () => { .expect('welcome') .expect(200, done); }); + + it('request to 3dAr.usdz', (done) => { + request(app).get('/3dAr.usdz') + .expect('Content-Type', 'model/vnd.pixar.usd') + .expect('010101') + .expect(200, done); + }); }); describe('MultiCompiler', () => {