Skip to content

Commit e353a9f

Browse files
fix. http relative path #1091
1 parent 77f05df commit e353a9f

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

.vscode/plugins.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@
113113
"yargs": "^17.7.2"
114114
},
115115
"browserslist": "cover 100%,not android < 5"
116-
}
116+
}

src/lib/run.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import $_console from "views/console.hbs";
1414
import $_markdown from "views/markdown.hbs";
1515
import constants from "./constants";
1616
import EditorFile from "./editorFile";
17-
import openFolder from "./openFolder";
17+
import openFolder, { addedFolder } from "./openFolder";
1818
import appSettings from "./settings";
1919

2020
/**@type {Server} */
@@ -172,14 +172,23 @@ async function run(
172172
* @param {string} req.requestId
173173
* @param {string} req.path
174174
*/
175-
function handleRequest(req) {
175+
async function handleRequest(req) {
176176
const reqId = req.requestId;
177177
let reqPath = req.path.substring(1);
178178

179-
if (!reqPath || reqPath.endsWith("/")) {
180-
reqPath += "index.html";
179+
//if (!reqPath || reqPath.endsWith("/")) {}
180+
181+
if (!reqPath) {
182+
console.error("Request path is empty");
183+
webServer?.send(reqId, {
184+
status: 404,
185+
body: "Please provide full path of the file",
186+
});
187+
return;
181188
}
182189

190+
191+
183192
const ext = Url.extname(reqPath);
184193
let url = null;
185194

@@ -250,7 +259,7 @@ async function run(
250259
let file = activeFile.SAFMode === "single" ? activeFile : null;
251260

252261
if (pathName) {
253-
url = Url.join(pathName, reqPath);
262+
url = Url.join(addedFolder[0].url, reqPath);
254263
file = editorManager.getFile(url, "uri");
255264
} else if (!activeFile.uri) {
256265
file = activeFile;
@@ -480,12 +489,18 @@ async function run(
480489
});
481490
}
482491

492+
function removePrefix(str, prefix) {
493+
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
494+
}
495+
483496
/**
484497
* Opens the preview in browser
485498
*/
486499
function openBrowser() {
487-
console.count("openBrowser");
488-
const src = `http://localhost:${port}/${filename}`;
500+
/** @type {string} */
501+
const filePath = pathName + filename;
502+
let path = removePrefix(removePrefix(filePath, addedFolder[0].url),"/");
503+
const src = `http://localhost:${port}/${path}`;
489504
if (target === "browser") {
490505
system.openInBrowser(src);
491506
return;

0 commit comments

Comments
 (0)