diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index 7c5d7b559df9c..abad677883798 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -1315,6 +1315,11 @@ export default class Server { return this.handleRequest(req, res, parsedUrl) } + // Custom server users can run `app.render()` which needs compression. + if (this.renderOpts.customServer) { + this.handleCompression(req, res) + } + if (isBlockedPage(pathname)) { return this.render404(req, res, parsedUrl) } diff --git a/test/integration/custom-server/test/index.test.js b/test/integration/custom-server/test/index.test.js index b1ffc4f0adb35..e4846692d5d6c 100644 --- a/test/integration/custom-server/test/index.test.js +++ b/test/integration/custom-server/test/index.test.js @@ -183,4 +183,17 @@ describe('Custom Server', () => { expect(stderr).toContain('Cannot render page with path "dashboard"') }) }) + + describe('compression handling', function () { + beforeAll(() => startServer()) + afterAll(() => killApp(server)) + + it.each(['/', '/no-query'])( + 'should handle compression for route %s', + async (route) => { + const response = await fetchViaHTTP(appPort, route) + expect(response.headers.get('Content-Encoding')).toBe('gzip') + } + ) + }) })