Transform HTML output of webapp to AMP

Currently, we forked the webapp package and added the handling here

return getBoilerplateAsync(request, arch)
        .then(async ({ stream, statusCode, headers: newHeaders }) => {
          if (!statusCode) {
            statusCode = res.statusCode ? res.statusCode : 200;
          }

          if (newHeaders) {
            Object.assign(headers, newHeaders);
          }

          res.writeHead(statusCode, headers);

          /* ===== Start of fork changes ===== */
          if (request?.path?.startsWith('/amp/')) {
            const [error, html] = await to(streamToString(stream));
            if (error) {
              debug.error(error);
            }

            const ampOptimizer = AmpOptimizer.create();
            const [err, amp] = await to(ampOptimizer.transformHtml(html));
            if (err) {
              debug.error(err);
            }

            res.write(amp);
            res.end();
            stream.destroy();
          } else {
          /* ===== End of fork changes ===== */

            stream.pipe(res, {
              // End the response when the stream ends.
              end: true
            });
          }
        })
        .catch(error => {
          Log.error('Error running template: ' + error.stack);
          res.writeHead(500, headers);
          res.end();
        });

Hopefully there is a cleaner way to do this without forking webapp