diff --git a/packages/cli/src/lifecycles/serve.js b/packages/cli/src/lifecycles/serve.js index f15107daa..da386eaaa 100644 --- a/packages/cli/src/lifecycles/serve.js +++ b/packages/cli/src/lifecycles/serve.js @@ -200,6 +200,8 @@ async function getStaticServer(compilation, composable) { await next(); }); + // TODO devServer.proxy is not really just for dev + // should it be renamed? should this be a middleware? app.use(async (ctx, next) => { try { const url = new URL(`http://localhost:${port}${ctx.url}`); diff --git a/packages/cli/src/plugins/resource/plugin-dev-proxy.js b/packages/cli/src/plugins/resource/plugin-dev-proxy.js index a85b1d5c9..37800a819 100644 --- a/packages/cli/src/plugins/resource/plugin-dev-proxy.js +++ b/packages/cli/src/plugins/resource/plugin-dev-proxy.js @@ -31,8 +31,18 @@ class DevProxyResource extends ResourceInterface { method: request.method, headers: request.header }); + const response = await fetch(requestProxied); + const filteredResponseHeaders = new Headers(); - return await fetch(requestProxied); + // filter out content-encoding to make sure browsers do not try and decode responses + // https://github.com/ProjectEvergreen/greenwood/issues/1159 + response.headers.forEach((value, key) => { + if (key !== 'content-encoding') { + filteredResponseHeaders.set(key, value); + } + }); + + return new Response(response.body, { headers: filteredResponseHeaders }); } } diff --git a/packages/cli/test/cases/develop.default/develop.default.spec.js b/packages/cli/test/cases/develop.default/develop.default.spec.js index 84837a0e7..d6845298e 100644 --- a/packages/cli/test/cases/develop.default/develop.default.spec.js +++ b/packages/cli/test/cases/develop.default/develop.default.spec.js @@ -1321,6 +1321,12 @@ describe('Develop Greenwood With: ', function() { done(); }); + // https://github.com/ProjectEvergreen/greenwood/issues/1159 + it('should not return a content-encoding header', function(done) { + expect(response.headers['content-encoding']).to.equal(undefined); + done(); + }); + it('should return the correct response body', function(done) { expect(response.body).to.have.lengthOf(1); done();