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
This commit is contained in:
Jeff Wong 2021-05-10 07:02:33 -10:00 committed by GitHub
parent 81616fbdc4
commit d61573fb1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View File

@ -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: {

View File

@ -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);
},
};