FIX: Already sent headers error in Ember CLI (#12706)

FIX: Already sent headers error in Ember CLI (#12706)

If we are sending a custom template, we shouldn’t do a next(), we should halt middleware.

diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
index 4bd268c..d2a7b78 100644
--- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
+++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
@@ -180,6 +180,7 @@ module.exports = {
         : cleanBaseURL(options.rootURL || options.baseURL);
 
     app.use(async (req, res, next) => {
+      let sentTemplate = false;
       try {
         const results = await watcher;
         if (this.shouldHandleRequest(req, options)) {
@@ -210,11 +211,14 @@ module.exports = {
                 </html>
               `;
             }
+            sentTemplate = true;
             return res.send(template);
           }
         }
       } finally {
-        next();
+        if (!sentTemplate) {
+          return next();
+        }
       }
     });
   },

GitHub sha: 32689573

This commit appears in #12706 which was approved by CvX. It was merged by eviltrout.