Next.js Discord

Discord Forum

Next.js + Custom express server

Unanswered
Hutton's Vireo posted this in #help-forum
Open in Discord
Hutton's VireoOP
I used custom express server with next.js to be able to modify page response. I want to apply external header and footer to some pages. I redefined write fn of response and collecting all chunks together if the functions was called with last chunk - apply external header/footer and return to user. The issue is (look at fn isLastChunk) when NODE_ENV=development chunks is utf-8, but when I change env to production all chunks are encoded and I'm not able to catch the last chunk.

function decodeChunk(chunk, encoding = 'utf-8') {
  const decoder = new TextDecoder(encoding);
  return decoder.decode(chunk);
}

function isLastChunk(chunk, encoding) {
  const chunkString = decodeChunk(chunk, encoding);
  return chunkString.endsWith('</html>');
}

2 Replies

Hutton's VireoOP
Here is the ends of chunks, 1 -dev, 2 - prod