Skip to content

Commit b135b3d

Browse files
gpoitchevilebottnawi
authored andcommitted
fix: don't add charset to usdz file type (#357)
1 parent c64a2c1 commit b135b3d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/middleware.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const mime = require('mime');
55
const DevMiddlewareError = require('./DevMiddlewareError');
66
const { getFilenameFromUrl, handleRangeHeaders, handleRequest, ready } = require('./util');
77

8+
// Do not add a charset to the Content-Type header of these file types
9+
// otherwise the client will fail to render them correctly.
10+
const NonCharsetFileTypes = /\.(wasm|usdz)$/;
11+
812
module.exports = function wrapper(context) {
913
return function middleware(req, res, next) {
1014
// fixes #282. credit @cexoso. in certain edge situations res.locals is
@@ -71,8 +75,7 @@ module.exports = function wrapper(context) {
7175

7276
let contentType = mime.getType(filename) || '';
7377

74-
// do not add charset to WebAssembly files, otherwise compileStreaming will fail in the client
75-
if (!/\.wasm$/.test(filename)) {
78+
if (!NonCharsetFileTypes.test(filename)) {
7679
contentType += '; charset=UTF-8';
7780
}
7881

test/tests/server.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,21 @@ describe('Server', () => {
312312
});
313313
});
314314

315-
describe('WebAssembly', () => {
315+
describe('Special file type headers', () => {
316316
before((done) => {
317317
app = express();
318318
const compiler = webpack(webpackConfig);
319319
instance = middleware(compiler, {
320320
stats: 'errors-only',
321-
logLevel
321+
logLevel,
322+
mimeTypes: {
323+
'model/vnd.pixar.usd': ['usdz']
324+
}
322325
});
323326
app.use(instance);
324327
listen = listenShorthand(done);
325328
instance.fileSystem.writeFileSync('/hello.wasm', 'welcome');
329+
instance.fileSystem.writeFileSync('/3dAr.usdz', '010101');
326330
});
327331
after(close);
328332

@@ -332,6 +336,13 @@ describe('Server', () => {
332336
.expect('welcome')
333337
.expect(200, done);
334338
});
339+
340+
it('request to 3dAr.usdz', (done) => {
341+
request(app).get('/3dAr.usdz')
342+
.expect('Content-Type', 'model/vnd.pixar.usd')
343+
.expect('010101')
344+
.expect(200, done);
345+
});
335346
});
336347

337348
describe('MultiCompiler', () => {

0 commit comments

Comments
 (0)