From aa81f8836ac2bc94ffd151470cc18adacc056d5f Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Tue, 20 May 2025 13:09:58 +0530 Subject: [PATCH 1/3] fix. http get always returning html --- src/lib/run.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/run.js b/src/lib/run.js index 1934d2e93..b804a3d8b 100644 --- a/src/lib/run.js +++ b/src/lib/run.js @@ -155,6 +155,7 @@ async function run( } function startServer() { + //isFallback = true; webServer?.stop(); webServer = CreateServer(port, openBrowser, onError); webServer.setOnRequestHandler(handleRequest); @@ -253,14 +254,16 @@ async function run( let file = activeFile.SAFMode === "single" ? activeFile : null; - if (pathName && isFallback) { + if (pathName) { const projectFolder = addedFolder[0]; - //set the root folder to the file parent if no project folder is set - let rootFolder = pathName; - if (projectFolder !== undefined) { + let rootFolder = ""; + if (projectFolder !== undefined && pathName.includes(projectFolder)) { rootFolder = projectFolder.url; + } else { + rootFolder = pathName; } + const query = url.split("?")[1]; //remove the query string if present this is needs to be removed because the url is not valid From 7789466c689d3610a90863e993a69d240d3df2a2 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Tue, 20 May 2025 16:48:36 +0530 Subject: [PATCH 2/3] fix. styles and javascript not loading --- src/lib/run.js | 64 +++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/lib/run.js b/src/lib/run.js index b804a3d8b..1687799fa 100644 --- a/src/lib/run.js +++ b/src/lib/run.js @@ -180,10 +180,15 @@ async function run( const reqId = req.requestId; let reqPath = req.path.substring(1); + console.log(`XREQPATH ${reqPath}`) + console.log(req) + if (!reqPath || (reqPath.endsWith("/") && reqPath.length === 1)) { reqPath = getRelativePath(); } + console.log(`XREQPATH1 ${reqPath}`) + const ext = Url.extname(reqPath); let url = null; @@ -256,37 +261,40 @@ async function run( if (pathName) { const projectFolder = addedFolder[0]; - + const query = url.split("?")[1]; let rootFolder = ""; - if (projectFolder !== undefined && pathName.includes(projectFolder)) { - rootFolder = projectFolder.url; + + if (projectFolder !== undefined && pathName.includes(projectFolder.url)) { + rootFolder = projectFolder.url; } else { - rootFolder = pathName; + rootFolder = pathName; } - - const query = url.split("?")[1]; - - //remove the query string if present this is needs to be removed because the url is not valid - if (rootFolder.startsWith("ftp:") || rootFolder.startsWith("sftp:")) { - if (rootFolder.includes("?")) { - rootFolder = rootFolder.split("?")[0]; - } + + if ((rootFolder.startsWith("ftp:") || rootFolder.startsWith("sftp:")) && rootFolder.includes("?")) { + rootFolder = rootFolder.split("?")[0]; } - - url = Url.join(rootFolder, reqPath); - - //attach the ftp query string to the url - if (query) { - url = `${url}?${query}`; + + + rootFolder = rootFolder.replace(/\/+$/, ""); // remove trailing slash + reqPath = reqPath.replace(/^\/+/, ""); // remove leading slash + + const rootParts = rootFolder.split("/"); + const pathParts = reqPath.split("/"); + + if (pathParts[0] === rootParts[rootParts.length - 1]) { + pathParts.shift(); } - - console.log("url", url); - + + const fullPath = Url.join(rootFolder, pathParts.join("/")); + + // Add back the query if present + url = query ? `${fullPath}?${query}` : fullPath; + file = editorManager.getFile(url, "uri"); - } else if (!activeFile.uri) { + } else if (!activeFile.uri) { file = activeFile; - } - + } + switch (ext) { case ".htm": case ".html": @@ -547,17 +555,15 @@ async function run( // Set the root folder to the file parent if no project folder is set let rootFolder = pathName; - if (projectFolder !== undefined) { + if (projectFolder !== undefined && pathName.includes(projectFolder)) { rootFolder = projectFolder.url; + }else{ + rootFolder = pathName } //make the uri absolute if necessary rootFolder = makeUriAbsoluteIfNeeded(rootFolder); - console.log("rootFolder", rootFolder); - console.log("pathName", pathName); - console.log("filename", filename); - // Parent of the file let filePath = pathName; From 52cdb70fecea282ffcad6527cda508bea0da701e Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Tue, 20 May 2025 17:04:29 +0530 Subject: [PATCH 3/3] format --- src/lib/run.js | 53 +++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/lib/run.js b/src/lib/run.js index 1687799fa..3f5e9ec36 100644 --- a/src/lib/run.js +++ b/src/lib/run.js @@ -180,14 +180,14 @@ async function run( const reqId = req.requestId; let reqPath = req.path.substring(1); - console.log(`XREQPATH ${reqPath}`) - console.log(req) + console.log(`XREQPATH ${reqPath}`); + console.log(req); if (!reqPath || (reqPath.endsWith("/") && reqPath.length === 1)) { reqPath = getRelativePath(); } - console.log(`XREQPATH1 ${reqPath}`) + console.log(`XREQPATH1 ${reqPath}`); const ext = Url.extname(reqPath); let url = null; @@ -263,38 +263,43 @@ async function run( const projectFolder = addedFolder[0]; const query = url.split("?")[1]; let rootFolder = ""; - - if (projectFolder !== undefined && pathName.includes(projectFolder.url)) { - rootFolder = projectFolder.url; + + if ( + projectFolder !== undefined && + pathName.includes(projectFolder.url) + ) { + rootFolder = projectFolder.url; } else { - rootFolder = pathName; + rootFolder = pathName; } - - if ((rootFolder.startsWith("ftp:") || rootFolder.startsWith("sftp:")) && rootFolder.includes("?")) { - rootFolder = rootFolder.split("?")[0]; + + if ( + (rootFolder.startsWith("ftp:") || rootFolder.startsWith("sftp:")) && + rootFolder.includes("?") + ) { + rootFolder = rootFolder.split("?")[0]; } - - + rootFolder = rootFolder.replace(/\/+$/, ""); // remove trailing slash - reqPath = reqPath.replace(/^\/+/, ""); // remove leading slash - + reqPath = reqPath.replace(/^\/+/, ""); // remove leading slash + const rootParts = rootFolder.split("/"); const pathParts = reqPath.split("/"); - + if (pathParts[0] === rootParts[rootParts.length - 1]) { - pathParts.shift(); + pathParts.shift(); } - + const fullPath = Url.join(rootFolder, pathParts.join("/")); - + // Add back the query if present url = query ? `${fullPath}?${query}` : fullPath; - + file = editorManager.getFile(url, "uri"); - } else if (!activeFile.uri) { + } else if (!activeFile.uri) { file = activeFile; - } - + } + switch (ext) { case ".htm": case ".html": @@ -557,8 +562,8 @@ async function run( let rootFolder = pathName; if (projectFolder !== undefined && pathName.includes(projectFolder)) { rootFolder = projectFolder.url; - }else{ - rootFolder = pathName + } else { + rootFolder = pathName; } //make the uri absolute if necessary