FIX: ember-cli proxy subfolder fix (#12996)

FIX: ember-cli proxy subfolder fix (#12996)

  • FIX: ember-cli proxy subfolder fix

  • REFACTOR: put rootURL setup in environment, update baseURL logic for subfolder

Correctly have ember understand and parse relative_url_root and use it in the dev server

diff --git a/app/assets/javascripts/discourse/config/environment.js b/app/assets/javascripts/discourse/config/environment.js
index e004e1e..f967255 100644
--- a/app/assets/javascripts/discourse/config/environment.js
+++ b/app/assets/javascripts/discourse/config/environment.js
@@ -4,7 +4,7 @@ module.exports = function (environment) {
   let ENV = {
     modulePrefix: "discourse",
     environment,
-    rootURL: "/",
+    rootURL: process.env.DISCOURSE_RELATIVE_URL_ROOT || "/",
     locationType: "auto",
     historySupportMiddleware: false,
     EmberENV: {
diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
index 0e8b503..3b97c65 100644
--- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
+++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js
@@ -155,26 +155,28 @@ function applyBootstrap(bootstrap, template, headers) {
   return template;
 }
 
-function buildFromBootstrap(assetPath, proxy, req, headers) {
+function buildFromBootstrap(assetPath, proxy, baseURL, req, headers) {
   // eslint-disable-next-line
   return new Promise((resolve, reject) => {
     fs.readFile(
       path.join(process.cwd(), "dist", assetPath),
       "utf8",
       (err, template) => {
-        getJSON(`${proxy}/bootstrap.json`, null, req.headers)
+        getJSON(`${proxy}${baseURL}bootstrap.json`, null, req.headers)
           .then((json) => {
             resolve(applyBootstrap(json.bootstrap, template, headers));
           })
           .catch((e) => {
-            reject(`Could not get ${proxy}/bootstrap.json\n\n${e.toString()}`);
+            reject(
+              `Could not get ${proxy}${baseURL}bootstrap.json\n\n${e.toString()}`
+            );
           });
       }
     );
   });
 }
 
-async function handleRequest(assetPath, proxy, req, res) {
+async function handleRequest(assetPath, proxy, baseURL, req, res) {
   if (assetPath.endsWith("tests/index.html")) {
     return;
   }
@@ -200,6 +202,7 @@ async function handleRequest(assetPath, proxy, req, res) {
           let json = await buildFromBootstrap(
             assetPath,
             proxy,
+            baseURL,
             req,
             response.headers
           );
@@ -264,7 +267,7 @@ to serve API requests. For example:
           if (!isFile) {
             assetPath = "index.html";
           }
-          await handleRequest(assetPath, proxy, req, res);
+          await handleRequest(assetPath, proxy, baseURL, req, res);
         }
       } finally {
         if (!res.headersSent) {
@@ -274,7 +277,7 @@ to serve API requests. For example:
     });
   },
 
-  shouldHandleRequest(req, options) {
+  shouldHandleRequest(req) {
     let acceptHeaders = req.headers.accept || [];
     let hasHTMLHeader = acceptHeaders.indexOf("text/html") !== -1;
     if (req.method !== "GET") {
@@ -292,11 +295,7 @@ to serve API requests. For example:
       return false;
     }
 
-    let baseURL =
-      options.rootURL === ""
-        ? "/"
-        : cleanBaseURL(options.rootURL || options.baseURL);
-    let baseURLRegexp = new RegExp(`^${baseURL}`);
+    let baseURLRegexp = new RegExp(`^/`);
     return baseURLRegexp.test(req.path);
   },
 };

GitHub sha: d61573fb

This commit appears in #12996 which was approved by CvX and eviltrout. It was merged by featheredtoast.