A platform for community discussion. Free, open, simple.
DEV: Fix alternative output directories in ember-cli proxy (#25291)
David Taylored2802eeb533
diff --git a/app/assets/javascripts/bootstrap-json/index.js b/app/assets/javascripts/bootstrap-json/index.jsindex bc27cac3739..6bc34b291e8 100644--- a/app/assets/javascripts/bootstrap-json/index.js+++ b/app/assets/javascripts/bootstrap-json/index.js@@ -10,8 +10,11 @@ const { env } = require("node:process");const { glob } = require("glob");const { HTMLRewriter } = require("html-rewriter-wasm");-async function listDistAssets() {- const files = await glob("**/*.js", { nodir: true, cwd: "dist/assets" });+async function listDistAssets(outputPath) {+ const files = await glob("**/*.js", {+ nodir: true,+ cwd: `${outputPath}/assets`,+ });return new Set(files);}@@ -89,7 +92,7 @@ function updateScriptReferences({});}-async function handleRequest(proxy, baseURL, req, res) {+async function handleRequest(proxy, baseURL, req, res, outputPath) {// x-forwarded-host is used in e.g. GitHub CodeSpaceslet originalHost = req.headers["x-forwarded-host"] || req.headers.host;@@ -178,8 +181,8 @@ async function handleRequest(proxy, baseURL, req, res) {if (isHTML) {const [responseText, chunkInfoText, distAssets] = await Promise.all([response.text(),- fsPromises.readFile("dist/assets.json", "utf-8"),- listDistAssets(),+ fsPromises.readFile(`${outputPath}/assets.json`, "utf-8"),+ listDistAssets(outputPath),]);const chunkInfos = JSON.parse(chunkInfoText);@@ -233,6 +236,7 @@ module.exports = {serverMiddleware(config) {const app = config.app;let { proxy, rootURL, baseURL } = config.options;+ const outputPath = config.options.path ?? config.options.outputPath;if (!proxy) {// eslint-disable-next-line no-console@@ -268,7 +272,7 @@ to serve API requests. For example:app.use(pathRestrictedRawMiddleware, async (req, res, next) => {try {if (this.shouldHandleRequest(req, baseURL)) {- await handleRequest(proxy, baseURL, req, res);+ await handleRequest(proxy, baseURL, req, res, outputPath);} else {// Fixes issues when using e.g. "localhost" instead of loopback IP addressreq.headers.host = "127.0.0.1";