Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions src/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ async function run(
}

function startServer() {
//isFallback = true;
webServer?.stop();
webServer = CreateServer(port, openBrowser, onError);
webServer.setOnRequestHandler(handleRequest);
Expand All @@ -179,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;

Expand Down Expand Up @@ -253,31 +259,41 @@ async function run(

let file = activeFile.SAFMode === "single" ? activeFile : null;

if (pathName && isFallback) {
if (pathName) {
const projectFolder = addedFolder[0];
const query = url.split("?")[1];
let rootFolder = "";

//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.url)
) {
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
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);
rootFolder = rootFolder.replace(/\/+$/, ""); // remove trailing slash
reqPath = reqPath.replace(/^\/+/, ""); // remove leading slash

const rootParts = rootFolder.split("/");
const pathParts = reqPath.split("/");

//attach the ftp query string to the url
if (query) {
url = `${url}?${query}`;
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) {
Expand Down Expand Up @@ -544,17 +560,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;

Expand Down